[vlc-commits] block: add block_FilePath() to load a file into a block_t

Rémi Denis-Courmont git at videolan.org
Sat Sep 29 18:14:26 CEST 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Sep 29 14:42:32 2012 +0300| [79139b20fb78def6a83bd3d1f70af5513231427a] | committer: Rémi Denis-Courmont

block: add block_FilePath() to load a file into a block_t

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=79139b20fb78def6a83bd3d1f70af5513231427a
---

 include/vlc_block.h |    1 +
 src/libvlccore.sym  |    1 +
 src/misc/block.c    |   29 ++++++++++++++++++++++++-----
 3 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/include/vlc_block.h b/include/vlc_block.h
index 6d3ae7b..b2b0c81 100644
--- a/include/vlc_block.h
+++ b/include/vlc_block.h
@@ -166,6 +166,7 @@ static inline void block_Release( block_t *p_block )
 VLC_API block_t *block_heap_Alloc(void *, size_t) VLC_USED VLC_MALLOC;
 VLC_API block_t *block_mmap_Alloc(void *addr, size_t length) VLC_USED VLC_MALLOC;
 VLC_API block_t *block_File(int fd) VLC_USED VLC_MALLOC;
+VLC_API block_t *block_FilePath(const char *) VLC_USED VLC_MALLOC;
 
 static inline void block_Cleanup (void *block)
 {
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index be48588..c7ec811 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -26,6 +26,7 @@ block_FifoPut
 block_FifoRelease
 block_FifoShow
 block_File
+block_FilePath
 block_heap_Alloc
 block_Init
 block_mmap_Alloc
diff --git a/src/misc/block.c b/src/misc/block.c
index e4850e0..b853d35 100644
--- a/src/misc/block.c
+++ b/src/misc/block.c
@@ -34,10 +34,11 @@
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif
+#include <fcntl.h>
 
 #include <vlc_common.h>
 #include <vlc_block.h>
-#include <vlc_fs.h> /* For 64-bits lseek() definition */
+#include <vlc_fs.h>
 
 /**
  * @section Block handling functions.
@@ -358,10 +359,13 @@ ssize_t pread (int fd, void *buf, size_t count, off_t offset)
 #endif
 
 /**
- * Loads a file into a block of memory. If possible a private file mapping is
- * created. Otherwise, the file is read normally. On 32-bits platforms, this
- * function will not work for very large files, due to memory space
- * constraints. Cancellation point.
+ * Loads a file into a block of memory through a file descriptor.
+ * If possible a private file mapping is created. Otherwise, the file is read
+ * normally. This function is a cancellation point.
+ *
+ * @note On 32-bits platforms,
+ * this function will not work for very large files,
+ * due to memory space constraints.
  *
  * @param fd file descriptor to load from
  * @return a new block with the file content at p_buffer, and file length at
@@ -434,6 +438,21 @@ block_t *block_File (int fd)
 }
 
 /**
+ * Loads a file into a block of memory from the file path.
+ * See also block_File().
+ */
+block_t *block_FilePath (const char *path)
+{
+    int fd = vlc_open (path, O_RDONLY);
+    if (fd == -1)
+        return NULL;
+
+    block_t *block = block_File (fd);
+    close (fd);
+    return block;
+}
+
+/**
  * @section Thread-safe block queue functions
  */
 



More information about the vlc-commits mailing list