FFmpeg 5.1.6
Functions
file.h File Reference

Misc file utilities. More...

#include <stddef.h>
#include <stdint.h>
#include "attributes.h"

Go to the source code of this file.

Functions

av_warn_unused_result 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. More...
 
void av_file_unmap (uint8_t *bufptr, size_t size)
 Unmap or free the buffer bufptr created by av_file_map(). More...
 
int av_tempfile (const char *prefix, char **filename, int log_offset, void *log_ctx)
 Wrapper to work around the lack of mkstemp() on mingw. More...
 

Detailed Description

Misc file utilities.

Definition in file file.h.

Function Documentation

◆ av_file_map()

av_warn_unused_result 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
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_reading.c.

Referenced by main().

◆ 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
sizesize in bytes of bufptr, must be the same as returned by av_file_map()
Examples
avio_reading.c.

Referenced by main().

◆ av_tempfile()

int av_tempfile ( const char *  prefix,
char **  filename,
int  log_offset,
void *  log_ctx 
)

Wrapper to work around the lack of mkstemp() on mingw.

Also, tries to create file in /tmp first, if possible. *prefix can be a character constant; *filename will be allocated internally.

Returns
file descriptor of opened file (or negative value corresponding to an AVERROR code on error) and opened file name in **filename.
Note
On very old libcs it is necessary to set a secure umask before calling this, av_tempfile() can't call umask itself as it is used in libraries and could interfere with the calling application.
Deprecated:
as fd numbers cannot be passed saftely between libs on some platforms