36#elif HAVE_MAPVIEWOFFILE
63#if HAVE_MMAP || HAVE_MAPVIEWOFFILE
67static int map_file(
int fd,
size_t size,
int shared,
void **ptr)
72 if (fstat(fd, &st) < 0)
74 if (st.st_size <
size && ftruncate(fd,
size) < 0)
78 void *
map = mmap(
NULL,
size, PROT_READ | PROT_WRITE,
79 shared ? MAP_SHARED : MAP_PRIVATE, fd, 0);
80 if (
map == MAP_FAILED)
83 HANDLE fh = (HANDLE)_get_osfhandle(fd);
84 if (fh == INVALID_HANDLE_VALUE)
87 HANDLE
mh = CreateFileMapping(fh,
NULL,
88 shared ? PAGE_READWRITE : PAGE_READONLY,
93 void *
map = MapViewOfFile(
mh, shared ? FILE_MAP_ALL_ACCESS : FILE_MAP_COPY,
104static void unmap_file(
void *ptr,
size_t size)
109 UnmapViewOfFile(ptr);
115 int log_offset,
void *log_ctx)
130 if (fstat(fd, &st) < 0) {
137 if (st.st_size > SIZE_MAX) {
139 "File size for file '%s' is too big\n", filename);
150#if HAVE_MMAP || HAVE_MAPVIEWOFFILE
151 err = map_file(fd, *
size, 0, &ptr);
177 if (!
size || !bufptr)
179#if HAVE_MMAP || HAVE_MAPVIEWOFFILE
180 unmap_file(bufptr,
size);
191#if HAVE_MMAP || HAVE_MAPVIEWOFFILE
192 return map_file(fd,
size, 1, bufptr);
200#if HAVE_MMAP || HAVE_MAPVIEWOFFILE
202 unmap_file(bufptr,
size);
static av_cold void close(AVCodecParserContext *s)
static uint32_t BS_FUNC read(BSCTX *bc, unsigned int n)
Return n bits from the buffer, n has to be in the 0-32 range.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
#define LIBAVUTIL_VERSION_INT
const VDPAUPixFmtMap * map
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, int log_offset, void *log_ctx)
Read the file with name filename, and put its content in a newly allocated buffer or map it with mmap...
static const AVClass file_log_ctx_class
int av_file_map_shared(int fd, size_t size, void **bufptr)
Map the beginning of an open file into memory for shared read and write access.
void av_file_unmap_shared(void *bufptr, size_t size)
Unmap the memory mapped by av_file_map_shared().
int avpriv_open(const char *filename, int flags,...)
A wrapper for open() setting O_CLOEXEC.
common internal API header
Memory handling functions.
Describe the class of an AVClass context structure.