Commit 79139b20 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont
Browse files

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

parent 5344b8e8
...@@ -166,6 +166,7 @@ static inline void block_Release( block_t *p_block ) ...@@ -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_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_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_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) static inline void block_Cleanup (void *block)
{ {
......
...@@ -26,6 +26,7 @@ block_FifoPut ...@@ -26,6 +26,7 @@ block_FifoPut
block_FifoRelease block_FifoRelease
block_FifoShow block_FifoShow
block_File block_File
block_FilePath
block_heap_Alloc block_heap_Alloc
block_Init block_Init
block_mmap_Alloc block_mmap_Alloc
......
...@@ -34,10 +34,11 @@ ...@@ -34,10 +34,11 @@
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
# include <unistd.h> # include <unistd.h>
#endif #endif
#include <fcntl.h>
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_block.h> #include <vlc_block.h>
#include <vlc_fs.h> /* For 64-bits lseek() definition */ #include <vlc_fs.h>
/** /**
* @section Block handling functions. * @section Block handling functions.
...@@ -358,10 +359,13 @@ ssize_t pread (int fd, void *buf, size_t count, off_t offset) ...@@ -358,10 +359,13 @@ ssize_t pread (int fd, void *buf, size_t count, off_t offset)
#endif #endif
/** /**
* Loads a file into a block of memory. If possible a private file mapping is * Loads a file into a block of memory through a file descriptor.
* created. Otherwise, the file is read normally. On 32-bits platforms, this * If possible a private file mapping is created. Otherwise, the file is read
* function will not work for very large files, due to memory space * normally. This function is a cancellation point.
* constraints. 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 * @param fd file descriptor to load from
* @return a new block with the file content at p_buffer, and file length at * @return a new block with the file content at p_buffer, and file length at
...@@ -433,6 +437,21 @@ block_t *block_File (int fd) ...@@ -433,6 +437,21 @@ block_t *block_File (int fd)
return block; return block;
} }
/**
* 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 * @section Thread-safe block queue functions
*/ */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment