summaryrefslogtreecommitdiffstats
path: root/libavutil
diff options
context:
space:
mode:
authorMarton Balint <cus@passwd.hu>2018-09-06 20:46:16 +0200
committerMarton Balint <cus@passwd.hu>2018-09-09 21:21:42 +0200
commit4737387d288d1e87e7c7df6203a42d6b1e88231e (patch)
tree69e773b38dc8136d3650947244b873321e679eca /libavutil
parentbd3c27fd7aa35ab3c0de03ffff598840634c7c2f (diff)
downloadffmpeg-streaming-4737387d288d1e87e7c7df6203a42d6b1e88231e.zip
ffmpeg-streaming-4737387d288d1e87e7c7df6203a42d6b1e88231e.tar.gz
avutil/file: allow mapping 0 byte files with av_file_map
Signed-off-by: Marton Balint <cus@passwd.hu>
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/file.c8
-rw-r--r--libavutil/file.h2
-rw-r--r--libavutil/version.h2
3 files changed, 11 insertions, 1 deletions
diff --git a/libavutil/file.c b/libavutil/file.c
index 24a86c3..d946085 100644
--- a/libavutil/file.c
+++ b/libavutil/file.c
@@ -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
diff --git a/libavutil/file.h b/libavutil/file.h
index 8666c7b..3ef4a60 100644
--- a/libavutil/file.h
+++ b/libavutil/file.h
@@ -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
diff --git a/libavutil/version.h b/libavutil/version.h
index 84409b1..f84ec89 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -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, \
OpenPOWER on IntegriCloud