]> git.sesse.net Git - ffmpeg/blob - libavutil/file_open.c
fate: Add h264 test for frame num gaps
[ffmpeg] / libavutil / file_open.c
1 /*
2  * This file is part of Libav.
3  *
4  * Libav is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * Libav is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with Libav; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18
19 #include "config.h"
20 #include "internal.h"
21 #include "mem.h"
22 #include <stdarg.h>
23 #include <fcntl.h>
24 #include <sys/stat.h>
25 #if HAVE_UNISTD_H
26 #include <unistd.h>
27 #endif
28 #if HAVE_IO_H
29 #include <io.h>
30 #endif
31
32 #if defined(_WIN32) && !defined(__MINGW32CE__)
33 #undef open
34 #undef lseek
35 #undef stat
36 #undef fstat
37 #include <windows.h>
38 #include <share.h>
39 #include <errno.h>
40 #include "wchar_filename.h"
41
42 static int win32_open(const char *filename_utf8, int oflag, int pmode)
43 {
44     int fd;
45     wchar_t *filename_w;
46
47     /* convert UTF-8 to wide chars */
48     if (utf8towchar(filename_utf8, &filename_w))
49         return -1;
50     if (!filename_w)
51         goto fallback;
52
53     fd = _wsopen(filename_w, oflag, SH_DENYNO, pmode);
54     av_freep(&filename_w);
55
56     if (fd != -1 || (oflag & O_CREAT))
57         return fd;
58
59 fallback:
60     /* filename may be be in CP_ACP */
61     return _sopen(filename_utf8, oflag, SH_DENYNO, pmode);
62 }
63 #define open win32_open
64 #endif
65
66 int avpriv_open(const char *filename, int flags, ...)
67 {
68     int fd;
69     unsigned int mode = 0;
70     va_list ap;
71
72     va_start(ap, flags);
73     if (flags & O_CREAT)
74         mode = va_arg(ap, unsigned int);
75     va_end(ap);
76
77 #ifdef O_CLOEXEC
78     flags |= O_CLOEXEC;
79 #endif
80
81     fd = open(filename, flags, mode);
82 #if HAVE_FCNTL
83     if (fd != -1)
84         fcntl(fd, F_SETFD, FD_CLOEXEC);
85 #endif
86
87     return fd;
88 }