FFmpeg
Loading...
Searching...
No Matches
file.c File Reference
#include "config.h"
#include "error.h"
#include "file.h"
#include "file_open.h"
#include "internal.h"
#include "log.h"
#include "mem.h"
#include <fcntl.h>
#include <sys/stat.h>

Go to the source code of this file.

Data Structures

struct  FileLogContext
 

Functions

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() when available.
 
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_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().
 

Variables

static const AVClass file_log_ctx_class
 

Function Documentation

◆ 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() 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().

Parameters
filenamepath to the file
[out]bufptrpointee is set to the mapped or allocated buffer
[out]sizepointee is set to the size in bytes of the buffer
log_offsetloglevel offset used for logging
log_ctxcontext used for logging
Returns
a non negative number in case of success, a negative value corresponding to an AVERROR error code in case of failure
Examples
avio_read_callback.c.

Definition at line 114 of file file.c.

Referenced by ff_load_textfile(), init(), init(), init_pattern_from_file(), init_pattern_from_file(), init_vulkan(), main(), main(), parse_custom_lut(), parse_psfile(), parse_psfile(), and read_shape_from_file().

◆ av_file_unmap()

void av_file_unmap ( uint8_t * bufptr,
size_t size )

Unmap or free the buffer bufptr created by av_file_map().

Parameters
bufptrthe buffer previously created with av_file_map()
sizesize in bytes of bufptr, must be the same as returned by av_file_map()
Examples
avio_read_callback.c.

Definition at line 175 of file file.c.

Referenced by ff_load_textfile(), init(), init(), init_vulkan(), main(), main(), parse_custom_lut(), parse_psfile(), parse_psfile(), read_shape_from_file(), uninit(), and uninit().

◆ av_file_map_shared()

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.

Unlike av_file_map() the mapping is not a private copy of the file, every store to the returned memory is written to the file and is visible to every other mapping of it, in this process and in other processes. The file is extended to size bytes if it is shorter, it is never shortened. The mapping must be released with av_file_unmap_shared().

Parameters
fdfile descriptor of a file opened for reading and writing
sizenumber of bytes to map, must not be zero
[out]bufptrpointee is set to the mapped memory
Returns
0 in case of success, a negative value corresponding to an AVERROR error code in case of failure, AVERROR(ENOSYS) when the platform has no shared file mappings

Definition at line 186 of file file.c.

Referenced by cache_map(), and spacemap_remap().

◆ av_file_unmap_shared()

void av_file_unmap_shared ( void * bufptr,
size_t size )

Unmap the memory mapped by av_file_map_shared().

Parameters
bufptrthe memory previously mapped by av_file_map_shared()
sizesize in bytes of the mapping, must be the same as passed to av_file_map_shared()

Definition at line 198 of file file.c.

Referenced by cache_map(), shared_close(), and spacemap_remap().

Variable Documentation

◆ file_log_ctx_class

const AVClass file_log_ctx_class
static
Initial value:
= {
.class_name = "FILE",
.item_name = av_default_item_name,
.option = NULL,
.log_level_offset_offset = 0x42 ,
.parent_log_context_offset = 0x42 ,
}
#define NULL
Definition coverity.c:32
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
#define LIBAVUTIL_VERSION_INT
Definition version.h:85

Definition at line 54 of file file.c.

Referenced by av_file_map(), and avpriv_tempfile().