[FFmpeg-devel] [libav-devel] [PATCH 1/3] Add avio_check() function.

Michael Niedermayer michaelni at gmx.at
Sun Apr 10 03:57:49 CEST 2011


On Sun, Apr 10, 2011 at 12:52:57AM +0200, Stefano Sabatini wrote:
> [CC-ing ffmpeg-devel]
> 
> On date Saturday 2011-04-09 12:35:58 +0200, Anton Khirnov wrote:
> > On Sat, Apr 09, 2011 at 02:47:35AM +0200, Stefano Sabatini wrote:
> > > From b563c12cb285f1e6eb8dc19d1a18323cd9280ea1 Mon Sep 17 00:00:00 2001
> > > From: Stefano Sabatini <stefano.sabatini-lala at poste.it>
> > > Date: Fri, 8 Apr 2011 18:32:25 +0200
> > > Subject: [PATCH] avio: add avio_check()
> > > 
> > > The new function is more flexible than url_exist(), as it allows to
> > > specify which access flags to check, and does not require an explicit
> > > open of the checked resource.
> > > ---
> > >  libavformat/avio.c |   19 +++++++++++++++++++
> > >  libavformat/avio.h |   15 +++++++++++++++
> > >  2 files changed, 34 insertions(+), 0 deletions(-)
> > > 
> > > diff --git a/libavformat/avio.c b/libavformat/avio.c
> > > index 7b066e3..cc57529 100644
> > > --- a/libavformat/avio.c
> > > +++ b/libavformat/avio.c
> > > @@ -362,6 +362,25 @@ int url_exist(const char *filename)
> > >      return 1;
> > >  }
> > >  
> > > +int avio_check(const char *url, int flags)
> > > +{
> > > +    URLContext *h;
> > > +    int ret = ffurl_alloc(&h, url, flags);
> > > +    if (ret)
> > > +        return ret;
> > > +
> > > +    if (h->prot->url_check) {
> > > +        ret = h->prot->url_check(h, flags);
> > > +    } else {
> > > +        ret = ffurl_connect(h);
> > > +        if (ret >= 0)
> > 
> > When is ret > 0? A quick glance at ffurl_connect suggests that it
> > returns 0 on success or an AVERROR < 0 on error.
> 
> The usual convenction is: >= 0 in case of success, < 0 in case of
> failure, even if the positive values are not used most of the times,
> so the check can't hurt.

yep, its also consistent throughout ffmpeg.
One immedeatly knows what a f()<0 or f()>=0 means even if one doesnt
know the API of f().
such consistent error handling thus makes teh code a (tiny) bit easier
to read

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

It is dangerous to be right in matters on which the established authorities
are wrong. -- Voltaire
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20110410/d50c151a/attachment.asc>


More information about the ffmpeg-devel mailing list