]> git.sesse.net Git - ffmpeg/commitdiff
avutil/file: allow mapping 0 byte files with av_file_map
authorMarton Balint <cus@passwd.hu>
Thu, 6 Sep 2018 18:46:16 +0000 (20:46 +0200)
committerMarton Balint <cus@passwd.hu>
Sun, 9 Sep 2018 19:21:42 +0000 (21:21 +0200)
Signed-off-by: Marton Balint <cus@passwd.hu>
libavutil/file.c
libavutil/file.h
libavutil/version.h

index 24a86c3f353f46be884a0e929c2cf66f8c3adcf3..d946085b280dfc9328a5aaa780b35e0175b6705d 100644 (file)
@@ -85,6 +85,11 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
     }
     *size = off_size;
 
+    if (!*size) {
+        *bufptr = NULL;
+        goto out;
+    }
+
 #if HAVE_MMAP
     ptr = mmap(NULL, *size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
     if (ptr == MAP_FAILED) {
@@ -126,12 +131,15 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
     read(fd, *bufptr, *size);
 #endif
 
+out:
     close(fd);
     return 0;
 }
 
 void av_file_unmap(uint8_t *bufptr, size_t size)
 {
+    if (!size)
+        return;
 #if HAVE_MMAP
     munmap(bufptr, size);
 #elif HAVE_MAPVIEWOFFILE
index 8666c7b1d5ee6e1a86a47734efb1d8e943f37f66..3ef4a6022cd08cb918f55a6b1c4c9facf68065c8 100644 (file)
@@ -33,6 +33,8 @@
  * allocated buffer or map it with mmap() when available.
  * In case of success set *bufptr to the read or mmapped buffer, and
  * *size to the size in bytes of the buffer in *bufptr.
+ * Unlike mmap this function succeeds with zero sized files, in this
+ * case *bufptr will be set to NULL and *size will be set to 0.
  * The returned buffer must be released with av_file_unmap().
  *
  * @param log_offset loglevel offset used for logging
index 84409b1d69dca645c819c8374313079ee30c0618..f84ec891544cef072087647951b01ecdc60e5d72 100644 (file)
@@ -80,7 +80,7 @@
 
 #define LIBAVUTIL_VERSION_MAJOR  56
 #define LIBAVUTIL_VERSION_MINOR  19
-#define LIBAVUTIL_VERSION_MICRO 100
+#define LIBAVUTIL_VERSION_MICRO 101
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
                                                LIBAVUTIL_VERSION_MINOR, \