[FFmpeg-devel] [PATCH 2/2] lavf/file: check for dirent.h support

Michael Niedermayer michaelni at gmx.at
Thu Jun 25 12:09:54 CEST 2015


On Wed, Jun 24, 2015 at 03:25:18AM +0200, Mariusz Szczepańczyk wrote:
> On Tue, Jun 23, 2015 at 8:34 PM, Michael Niedermayer <michaelni at gmx.at>
> wrote:
> 
> > On Mon, Jun 22, 2015 at 12:01:33AM +0200, Mariusz Szczepańczyk wrote:
> > > ---
> > >  configure          |  2 ++
> > >  libavformat/file.c | 34 ++++++++++++++++++++++++++++++++++
> > >  2 files changed, 36 insertions(+)
> >
> > this and the previous patch fails to build
> >
> > make distclean ; ./configure --disable-sdl && make -j12
> >
> > libavformat/file.c: In function ‘file_read_dir’:
> > libavformat/file.c:302:10: error: ‘DT_FIFO’ undeclared (first use in this
> > function)
> > libavformat/file.c:302:10: note: each undeclared identifier is reported
> > only once for each function it appears in
> > libavformat/file.c:305:10: error: ‘DT_CHR’ undeclared (first use in this
> > function)
> > libavformat/file.c:308:10: error: ‘DT_DIR’ undeclared (first use in this
> > function)
> > libavformat/file.c:311:10: error: ‘DT_BLK’ undeclared (first use in this
> > function)
> > libavformat/file.c:314:10: error: ‘DT_REG’ undeclared (first use in this
> > function)
> > libavformat/file.c:317:10: error: ‘DT_LNK’ undeclared (first use in this
> > function)
> > libavformat/file.c:320:10: error: ‘DT_SOCK’ undeclared (first use in this
> > function)
> > libavformat/file.c:323:10: error: ‘DT_UNKNOWN’ undeclared (first use in
> > this function)
> > make: *** [libavformat/file.o] Error 1
> > make: *** Waiting for unfinished jobs....
> >
> > sdl disable is needed to reproduce  as sdls pkgcnonfig adds
> > GNU_SOURCE i suspect
> >
> 
> Added contraint on _GNU_SOURCE and now it compiles fine on my linux in both
> cases (with or without sdl).

The code probably should #ifdef DT_... like DT_FIFO
also are both variants needed ?
are there systems lacking some of the S_IS*() ? or is there some
disadvantage in their use ? (i dont know, just asking ...)

testing for _GNU_SOURCE is not correct, nothing gurantees that the
compiler or headers know or react to _GNU_SOURCE


> 
> I've sent two patches to keep my and Lukasz's work separated. Of course I
> can squash them if you like.
> 
> Mariusz

>  configure          |    2 ++
>  libavformat/file.c |   34 ++++++++++++++++++++++++++++++++++
>  2 files changed, 36 insertions(+)
> 55b72496abeb2998a8c888cd56983184c91af6bb  0002-lavf-file-check-for-dirent.h-support.patch
> From aa9ee21be55e565362740791a949b97e88631168 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Mariusz=20Szczepa=C5=84czyk?= <mszczepanczyk at gmail.com>
> Date: Wed, 10 Jun 2015 03:30:29 +0200
> Subject: [PATCH 2/2] lavf/file: check for dirent.h support
> 
> ---
>  configure          |  2 ++
>  libavformat/file.c | 34 ++++++++++++++++++++++++++++++++++
>  2 files changed, 36 insertions(+)
> 
> diff --git a/configure b/configure
> index 0620936..069e997 100755
> --- a/configure
> +++ b/configure
> @@ -1681,6 +1681,7 @@ HEADERS_LIST="
>      dev_video_bktr_ioctl_bt848_h
>      dev_video_meteor_ioctl_meteor_h
>      direct_h
> +    dirent_h
>      dlfcn_h
>      d3d11_h
>      dxva_h
> @@ -4995,6 +4996,7 @@ enabled xlib &&
>      check_func_headers "X11/Xlib.h X11/extensions/Xvlib.h" XvGetPortAttribute -lXv -lX11 -lXext
>  
>  check_header direct.h
> +check_header dirent.h
>  check_header dlfcn.h
>  check_header d3d11.h
>  check_header dxva.h
> diff --git a/libavformat/file.c b/libavformat/file.c
> index 407540c..37da985 100644
> --- a/libavformat/file.c
> +++ b/libavformat/file.c
> @@ -23,7 +23,9 @@
>  #include "libavutil/internal.h"
>  #include "libavutil/opt.h"
>  #include "avformat.h"
> +#if HAVE_DIRENT_H
>  #include <dirent.h>
> +#endif
>  #include <fcntl.h>
>  #if HAVE_IO_H
>  #include <io.h>
> @@ -52,7 +54,9 @@ typedef struct FileContext {
>      int fd;
>      int trunc;
>      int blocksize;
> +#if HAVE_DIRENT_H
>      DIR *dir;
> +#endif
>  } FileContext;
>  
>  static const AVOption file_options[] = {
> @@ -229,6 +233,7 @@ static int file_close(URLContext *h)
>  
>  static int file_open_dir(URLContext *h)
>  {
> +#if HAVE_DIRENT_H
>      FileContext *c = h->priv_data;
>  
>      c->dir = opendir(h->filename);
> @@ -236,10 +241,14 @@ static int file_open_dir(URLContext *h)
>          return AVERROR(errno);
>  
>      return 0;
> +#else
> +    return AVERROR(ENOSYS);
> +#endif /* HAVE_DIRENT_H */
>  }
>  
>  static int file_read_dir(URLContext *h, AVIODirEntry **next)
>  {
> +#if HAVE_DIRENT_H
>      FileContext *c = h->priv_data;
>      struct dirent *dir;
>      char *fullpath = NULL;
> @@ -267,11 +276,28 @@ static int file_read_dir(URLContext *h, AVIODirEntry **next)
>              (*next)->modification_timestamp = INT64_C(1000000) * st.st_mtime;
>              (*next)->access_timestamp =  INT64_C(1000000) * st.st_atime;
>              (*next)->status_change_timestamp = INT64_C(1000000) * st.st_ctime;
> +
> +#if !defined(_DIRENT_HAVE_D_TYPE) || !defined(_GNU_SOURCE)
> +            if (S_ISDIR(st.st_mode))
> +                (*next)->type = AVIO_ENTRY_DIRECTORY;
> +            else if (S_ISFIFO(st.st_mode))
> +                (*next)->type = AVIO_ENTRY_NAMED_PIPE;
> +            else if (S_ISCHR(st.st_mode))
> +                (*next)->type = AVIO_ENTRY_CHARACTER_DEVICE;
> +            else if (S_ISBLK(st.st_mode))
> +                (*next)->type = AVIO_ENTRY_BLOCK_DEVICE;
> +            else if (S_ISREG(st.st_mode))
> +                (*next)->type = AVIO_ENTRY_FILE;
> +            else
> +                (*next)->type = AVIO_ENTRY_UNKNOWN;

S_ISLNK() S_ISSOCK() are missing (these may need some kind of
availability checks)

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Why not whip the teacher when the pupil misbehaves? -- Diogenes of Sinope
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150625/00ffa6d3/attachment.asc>


More information about the ffmpeg-devel mailing list