[FFmpeg-devel] [PATCH] lavu: add av_file_exists function

Stefano Sabatini stefasab at gmail.com
Tue Nov 5 12:00:49 CET 2013


On date Monday 2013-11-04 23:52:57 +0100, Lukasz Marek encoded:
> Signed-off-by: Lukasz Marek <lukasz.m.luki at gmail.com>
> ---
>  doc/APIchanges      |    3 +++
>  libavutil/file.c    |   20 ++++++++++++++++++++
>  libavutil/file.h    |    8 ++++++++
>  libavutil/version.h |    2 +-
>  4 files changed, 32 insertions(+), 1 deletion(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index dfdc159..0e91ba9 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -15,6 +15,9 @@ libavutil:     2012-10-22
>  
>  API changes, most recent first:
>  
> +2013-11-xx - xxxxxxx - lavu 52.52.100 - file.h
> +  Add av_file_exists()
> +
>  2013-11-xx - xxxxxxx - lavc 55.41.100 / 55.25.0 - avcodec.h
>                         lavu 52.51.100 - frame.h
>    Add ITU-R BT.2020 and other not yet included values to color primaries,
> diff --git a/libavutil/file.c b/libavutil/file.c
> index 45fe853..c91146d 100644
> --- a/libavutil/file.c
> +++ b/libavutil/file.c
> @@ -184,6 +184,20 @@ int av_tempfile(const char *prefix, char **filename, int log_offset, void *log_c
>      return fd; /* success */
>  }
>  
> +int av_file_exists(const char *filename)
> +{
> +#if HAVE_ACCESS
> +    if (access(filename, F_OK) < 0)
> +        return 0;
> +#else
> +    struct stat st;
> +    int ret = stat(filename, &st);
> +    if (ret < 0)
> +        return 0;
> +#endif
> +    return 1;
> +}
> +
>  #ifdef TEST
>  
>  #undef printf
> @@ -192,6 +206,12 @@ int main(void)
>  {
>      uint8_t *buf;
>      size_t size;
> +
> +    if (!av_file_exists("file.c"))
> +        return 1;
> +    if (!av_file_exists("../libavutil"))
> +        return 1;
> +
>      if (av_file_map("file.c", &buf, &size, 0, NULL) < 0)
>          return 1;
>  
> diff --git a/libavutil/file.h b/libavutil/file.h
> index a7364fe..a5199e0 100644
> --- a/libavutil/file.h
> +++ b/libavutil/file.h
> @@ -63,4 +63,12 @@ void av_file_unmap(uint8_t *bufptr, size_t size);
>   */
>  int av_tempfile(const char *prefix, char **filename, int log_offset, void *log_ctx);
>  
> +/**
> + * Checks existence of the file.
> + *
> + * @param filename file to be checked.
> + * @return 1 when file exists, 0 otherwise.
> + */
> +int av_file_exists(const char *filename);

Probably checking permissions would be more useful:
175389c85487822f1ee180ee01cc770df896557f
-- 
FFmpeg = Frenzy and Frightening MultiPurpose EntanGlement


More information about the ffmpeg-devel mailing list