windows support: fix _wstat misusage
[mplayer.git] / osdep / io.h
bloba1fd27325ea3cac92114832df3ea26dfad303896
1 /*
2 * unicode/utf-8 I/O helpers and wrappers for Windows
4 * This file is part of mplayer2.
6 * mplayer2 is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * mplayer2 is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with mplayer2. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef MPLAYER_OSDEP_IO
21 #define MPLAYER_OSDEP_IO
23 #include <limits.h>
25 #ifdef _WIN32
26 #include <wchar.h>
27 wchar_t *mp_from_utf8(void *talloc_ctx, const char *s);
28 char *mp_to_utf8(void *talloc_ctx, const wchar_t *s);
29 #endif
31 #ifdef __MINGW32__
33 #include <stdio.h>
34 #include <dirent.h>
35 #include <sys/stat.h>
36 #include <fcntl.h>
38 // Windows' MAX_PATH/PATH_MAX/FILENAME_MAX is fixed to 260, but this limit
39 // applies to unicode paths encoded with wchar_t (2 bytes on Windows). The UTF-8
40 // version could end up bigger in memory. In the worst case each wchar_t is
41 // encoded to 3 bytes in UTF-8, so in the worst case we have:
42 // wcslen(wpath) <= strlen(utf8path) * 3
43 // Thus we need MP_PATH_MAX as the UTF-8/char version of PATH_MAX.
44 #define MP_PATH_MAX (FILENAME_MAX * 3)
46 void mp_get_converted_argv(int *argc, char ***argv);
48 int mp_stat(const char *path, struct stat *buf);
49 int mp_fprintf(FILE *stream, const char *format, ...);
50 int mp_open(const char *filename, int oflag, ...);
51 int mp_creat(const char *filename, int mode);
52 FILE *mp_fopen(const char *filename, const char *mode);
53 DIR *mp_opendir(const char *path);
54 struct dirent *mp_readdir(DIR *dir);
55 int mp_closedir(DIR *dir);
56 int mp_mkdir(const char *path, int mode);
58 // NOTE: stat is not overridden with mp_stat, because MinGW-w64 defines it as
59 // macro.
61 #define fprintf(...) mp_fprintf(__VA_ARGS__)
62 #define open(...) mp_open(__VA_ARGS__)
63 #define creat(...) mp_creat(__VA_ARGS__)
64 #define fopen(...) mp_fopen(__VA_ARGS__)
65 #define opendir(...) mp_opendir(__VA_ARGS__)
66 #define readdir(...) mp_readdir(__VA_ARGS__)
67 #define closedir(...) mp_closedir(__VA_ARGS__)
68 #define mkdir(...) mp_mkdir(__VA_ARGS__)
70 #else /* __MINGW32__ */
72 #define MP_PATH_MAX PATH_MAX
74 #define mp_stat(...) stat(__VA_ARGS__)
76 #endif /* __MINGW32__ */
78 #endif