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

Lukasz Marek lukasz.m.luki at gmail.com
Mon Nov 4 23:52:57 CET 2013


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);
+
 #endif /* AVUTIL_FILE_H */
diff --git a/libavutil/version.h b/libavutil/version.h
index 2f91fc0..2859f5f 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -75,7 +75,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  52
-#define LIBAVUTIL_VERSION_MINOR  51
+#define LIBAVUTIL_VERSION_MINOR  52
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
1.7.10.4



More information about the ffmpeg-devel mailing list