mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-13 21:28:01 +02:00
Merge commit '869b04e89154cd92d2bcfdabcecbe3217864c099'
* commit '869b04e89154cd92d2bcfdabcecbe3217864c099': libavutil: add avpriv_open() to open files with close-on-exec flag Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
commit
5f38317e59
@ -18,8 +18,10 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
|
#include "internal.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
|
#include <stdarg.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#if HAVE_UNISTD_H
|
#if HAVE_UNISTD_H
|
||||||
@ -34,6 +36,27 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int avpriv_open(const char *filename, int flags, ...)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
unsigned int mode = 0;
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, flags);
|
||||||
|
if (flags & O_CREAT)
|
||||||
|
mode = va_arg(ap, unsigned int);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
#ifdef O_CLOEXEC
|
||||||
|
flags |= O_CLOEXEC;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
fd = open(filename, flags, mode);
|
||||||
|
if (fd != -1)
|
||||||
|
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const AVClass *class;
|
const AVClass *class;
|
||||||
int log_offset;
|
int log_offset;
|
||||||
@ -49,7 +72,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
|
|||||||
int log_offset, void *log_ctx)
|
int log_offset, void *log_ctx)
|
||||||
{
|
{
|
||||||
FileLogContext file_log_ctx = { &file_log_ctx_class, log_offset, log_ctx };
|
FileLogContext file_log_ctx = { &file_log_ctx_class, log_offset, log_ctx };
|
||||||
int err, fd = open(filename, O_RDONLY);
|
int err, fd = avpriv_open(filename, O_RDONLY);
|
||||||
struct stat st;
|
struct stat st;
|
||||||
av_unused void *ptr;
|
av_unused void *ptr;
|
||||||
off_t off_size;
|
off_t off_size;
|
||||||
|
@ -198,4 +198,9 @@ void avpriv_report_missing_feature(void *avc,
|
|||||||
void avpriv_request_sample(void *avc,
|
void avpriv_request_sample(void *avc,
|
||||||
const char *msg, ...) av_printf_format(2, 3);
|
const char *msg, ...) av_printf_format(2, 3);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A wrapper for open() setting O_CLOEXEC.
|
||||||
|
*/
|
||||||
|
int avpriv_open(const char *filename, int flags, ...);
|
||||||
|
|
||||||
#endif /* AVUTIL_INTERNAL_H */
|
#endif /* AVUTIL_INTERNAL_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user