On 06/08/13 20:19, Rémi Denis-Courmont wrote:
> ---
>  libavutil/file.c | 24 +++++++++++++++++++++++-
>  libavutil/file.h |  2 ++
>  2 files changed, 25 insertions(+), 1 deletion(-)
> 
> diff --git a/libavutil/file.c b/libavutil/file.c
> index ce02487..8b449f1 100644
> --- a/libavutil/file.c
> +++ b/libavutil/file.c
> @@ -20,6 +20,7 @@
>  #include "file.h"
>  #include "log.h"
>  #include "mem.h"
> +#include <stdarg.h>
>  #include <fcntl.h>
>  #include <sys/stat.h>
>  #if HAVE_UNISTD_H
> @@ -34,6 +35,27 @@
>  #include <windows.h>
>  #endif
>  
> +int avpriv_open(const char *filename, int flags, ...)
> +{
> +    int fd;
> +    unsigned int mode = 0;
> +    va_list ap;
> +
> +    va_start(ap, flags);
> +    if (flags & O_CREAT)
> +        mode = va_arg(ap, unsigned int);
> +    va_end(ap);
> +
> +#ifdef O_CLOEXEC
> +    flags |= O_CLOEXEC;
> +#endif
> +
> +    fd = open(filename, flags, mode);
> +    if (fd != -1)
> +        fcntl(fd, F_SETFD, FD_CLOEXEC);
> +    return fd;
> +}
> +
>  typedef struct {
>      const AVClass *class;
>      int   log_offset;
> @@ -49,7 +71,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, 
> size_t *size,
>                  int log_offset, void *log_ctx)
>  {
>      FileLogContext file_log_ctx = { &file_log_ctx_class, log_offset, log_ctx 
> };
> -    int err, fd = open(filename, O_RDONLY);
> +    int err, fd = avpriv_open(filename, O_RDONLY);
>      struct stat st;
>      av_unused void *ptr;
>      off_t off_size;
> diff --git a/libavutil/file.h b/libavutil/file.h
> index e3f02a8..c0e0873 100644
> --- a/libavutil/file.h
> +++ b/libavutil/file.h
> @@ -28,6 +28,8 @@
>   * Misc file utilities.
>   */
>  
> +int avpriv_open(const char *filename, int flags, ...);
> +

According to the discussion on irc, it should go in internal.h

while at it add

/**
 * Wrap the normal open call adding os-dependent flags such as
 * O_CLOEXEC.
 */

lu
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to