[FFmpeg-devel] [PATCH] avutil: add av_fopen_utf8()

Michael Niedermayer michaelni at gmx.at
Sun Nov 3 15:06:37 CET 2013


On Sun, Nov 03, 2013 at 11:28:45AM +0100, Stefano Sabatini wrote:
> On date Saturday 2013-11-02 01:48:19 +0100, Michael Niedermayer encoded:
> > fopen() on windows uses UTF-16, we use UTF-8 everywhere, this
> > function bridges the gap by using avpriv_open()
> > 
> > Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> > ---
> >  libavutil/avutil.h    |    7 +++++++
> >  libavutil/file_open.c |   34 ++++++++++++++++++++++++++++++++++
> >  2 files changed, 41 insertions(+)
> 
> Reminder: missing lavu minor bump, APIchanges entry.
> 
> > 
> > diff --git a/libavutil/avutil.h b/libavutil/avutil.h
> > index 4692c00..4e680ed 100644
> > --- a/libavutil/avutil.h
> > +++ b/libavutil/avutil.h
> > @@ -313,6 +313,13 @@ unsigned av_int_list_length_for_size(unsigned elsize,
> >      av_int_list_length_for_size(sizeof(*(list)), list, term)
> >  
> >  /**
> > + * Open a file using a UTF-8 filename.
> > + * The API of this function matches POSIX fopen(), errors are returned through
> > + * errno.
> > + */
> > +FILE *av_fopen_utf8(const char *path, const char *mode);
> > +
> > +/**
> >   * @}
> >   * @}
> >   */

> > diff --git a/libavutil/file_open.c b/libavutil/file_open.c
> > index 389076f..bcdd26a 100644
> > --- a/libavutil/file_open.c
> > +++ b/libavutil/file_open.c
> > @@ -93,3 +93,37 @@ int avpriv_open(const char *filename, int flags, ...)
> >  
> >      return fd;
> >  }
> > +
> > +FILE *av_fopen_utf8(const char *path, const char *mode)
> > +{
> > +    int fd;
> > +    int access;
> > +    const char *m = mode;
> > +
> > +    switch (*m++) {
> > +    case 'r': access = O_RDONLY; break;
> > +    case 'w': access = O_CREAT|O_WRONLY|O_TRUNC; break;
> > +    case 'a': access = O_CREAT|O_WRONLY|O_APPEND; break;
> > +    default :
> > +        errno = EINVAL;
> > +        return NULL;
> > +    }
> > +    while (*m) {
> > +        if (*m == '+') {
> > +            access &= ~(O_RDONLY | O_WRONLY);
> > +            access |= O_RDWR;
> > +        } else if (*m == 'b') {
> > +#ifdef O_BINARY
> > +            access |= O_BINARY;
> > +#endif
> > +        } else if (*m) {
> > +            errno = EINVAL;
> > +            return NULL;
> > +        }
> > +        m++;
> > +    }
> 
> Note: this is accepting things of the type "rb+" which are not
> strictly compliant.

please elaborate, i see "rb+" on:
http://pubs.opengroup.org/onlinepubs/009695399/functions/fopen.html


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

Its not that you shouldnt use gotos but rather that you should write
readable code and code with gotos often but not always is less readable
-------------- 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/20131103/013cc276/attachment.asc>


More information about the ffmpeg-devel mailing list