f3164ebe6846d19e6240b4d826d4cc185d5b6d5d
2 * This file is part of FFmpeg.
4 * FFmpeg 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.
9 * FFmpeg 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.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
32 #if defined(_WIN32) && !defined(__MINGW32CE__)
41 static int win32_open(const char *filename_utf8
, int oflag
, int pmode
)
47 /* convert UTF-8 to wide chars */
48 num_chars
= MultiByteToWideChar(CP_UTF8
, MB_ERR_INVALID_CHARS
, filename_utf8
, -1, NULL
, 0);
51 filename_w
= av_mallocz_array(num_chars
, sizeof(wchar_t));
56 MultiByteToWideChar(CP_UTF8
, 0, filename_utf8
, -1, filename_w
, num_chars
);
58 fd
= _wsopen(filename_w
, oflag
, SH_DENYNO
, pmode
);
59 av_freep(&filename_w
);
61 if (fd
!= -1 || (oflag
& O_CREAT
))
65 /* filename may be in CP_ACP */
66 return _sopen(filename_utf8
, oflag
, SH_DENYNO
, pmode
);
68 #define open win32_open
71 int avpriv_open(const char *filename
, int flags
, ...)
74 unsigned int mode
= 0;
79 mode
= va_arg(ap
, unsigned int);
86 fd
= open(filename
, flags
, mode
);
89 if (fcntl(fd
, F_SETFD
, FD_CLOEXEC
) == -1)
90 av_log(NULL
, AV_LOG_DEBUG
, "Failed to set close on exec\n");
97 FILE *av_fopen_utf8(const char *path
, const char *mode
)
101 const char *m
= mode
;
104 case 'r': access
= O_RDONLY
; break;
105 case 'w': access
= O_CREAT
|O_WRONLY
|O_TRUNC
; break;
106 case 'a': access
= O_CREAT
|O_WRONLY
|O_APPEND
; break;
113 access
&= ~(O_RDONLY
| O_WRONLY
);
115 } else if (*m
== 'b') {
125 fd
= avpriv_open(path
, access
, 0666);
128 return fdopen(fd
, mode
);