summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--input/input.c15
-rw-r--r--libmpcodecs/vf_remove_logo.c2
-rw-r--r--libmpdemux/demux_mf.c13
-rw-r--r--libmpdemux/mf.c19
-rw-r--r--libvo/vo_jpeg.c7
-rw-r--r--libvo/vo_pnm.c8
-rw-r--r--mplayer.c19
-rw-r--r--osdep/io.c185
-rw-r--r--osdep/io.h76
-rw-r--r--parser-cfg.c2
-rw-r--r--path.c18
-rw-r--r--path.h4
-rw-r--r--screenshot.c11
-rw-r--r--stream/cookies.c2
-rw-r--r--stream/stream_cddb.c10
-rw-r--r--stream/stream_file.c2
-rw-r--r--sub/find_subfiles.c2
-rw-r--r--sub/font_load.c10
-rw-r--r--timeline/tl_matroska.c2
20 files changed, 342 insertions, 66 deletions
diff --git a/Makefile b/Makefile
index 80708c29bc..21191655e7 100644
--- a/Makefile
+++ b/Makefile
@@ -403,6 +403,7 @@ SRCS_COMMON = asxparser.c \
libmpdemux/yuv4mpeg_ratio.c \
libvo/osd.c \
osdep/numcores.c \
+ osdep/io.c \
osdep/$(GETCH) \
osdep/$(TIMER) \
stream/open.c \
diff --git a/input/input.c b/input/input.c
index e1c001077a..cde1b5e027 100644
--- a/input/input.c
+++ b/input/input.c
@@ -31,6 +31,8 @@
#include <ctype.h>
#include <assert.h>
+#include "osdep/io.h"
+
#include "input.h"
#include "mp_fifo.h"
#include "keycodes.h"
@@ -1776,13 +1778,16 @@ struct input_ctx *mp_input_init(struct input_conf *input_conf)
#endif
if (input_conf->in_file) {
- struct stat st;
- int mode = O_RDONLY | O_NONBLOCK;
+ int mode = O_RDONLY;
+#ifndef __MINGW32__
// Use RDWR for FIFOs to ensure they stay open over multiple accesses.
- // Note that on Windows stat may fail for named pipes,
- // but due to how the API works, using RDONLY should be ok.
+ // Note that on Windows due to how the API works, using RDONLY should
+ // be ok.
+ struct stat st;
if (stat(input_conf->in_file, &st) == 0 && S_ISFIFO(st.st_mode))
- mode = O_RDWR | O_NONBLOCK;
+ mode = O_RDWR;
+ mode |= O_NONBLOCK;
+#endif
int in_file_fd = open(input_conf->in_file, mode);
if (in_file_fd >= 0)
mp_input_add_cmd_fd(ictx, in_file_fd, 1, NULL, close);
diff --git a/libmpcodecs/vf_remove_logo.c b/libmpcodecs/vf_remove_logo.c
index da90d3c066..1270f5e6c9 100644
--- a/libmpcodecs/vf_remove_logo.c
+++ b/libmpcodecs/vf_remove_logo.c
@@ -86,6 +86,8 @@
#include <ctype.h>
#include <inttypes.h>
+#include "osdep/io.h"
+
#include "config.h"
#include "mp_msg.h"
#include "libvo/fastmemcpy.h"
diff --git a/libmpdemux/demux_mf.c b/libmpdemux/demux_mf.c
index f47a11eed6..193b17bc18 100644
--- a/libmpdemux/demux_mf.c
+++ b/libmpdemux/demux_mf.c
@@ -23,6 +23,8 @@
#include <sys/stat.h>
#include <unistd.h>
+#include "osdep/io.h"
+
#include "talloc.h"
#include "config.h"
#include "mp_msg.h"
@@ -49,20 +51,19 @@ static void demux_seek_mf(demuxer_t *demuxer,float rel_seek_secs,float audio_del
// 1 = successfully read a packet
static int demux_mf_fill_buffer(demuxer_t *demuxer, demux_stream_t *ds){
mf_t * mf;
- struct stat fs;
FILE * f;
mf=(mf_t*)demuxer->priv;
if ( mf->curr_frame >= mf->nr_of_files ) return 0;
- stat( mf->names[mf->curr_frame],&fs );
-// printf( "[demux_mf] frame: %d (%s,%d)\n",mf->curr_frame,mf->names[mf->curr_frame],fs.st_size );
-
if ( !( f=fopen( mf->names[mf->curr_frame],"rb" ) ) ) return 0;
{
sh_video_t * sh_video = demuxer->video->sh;
- demux_packet_t * dp = new_demux_packet( fs.st_size );
- if ( !fread( dp->buffer,fs.st_size,1,f ) ) return 0;
+ fseek(f, 0, SEEK_END);
+ long file_size = ftell(f);
+ fseek(f, 0, SEEK_SET);
+ demux_packet_t * dp = new_demux_packet( file_size );
+ if ( !fread( dp->buffer,file_size,1,f ) ) return 0;
dp->pts=mf->curr_frame / sh_video->fps;
dp->pos=mf->curr_frame;
dp->flags=0;
diff --git a/libmpdemux/mf.c b/libmpdemux/mf.c
index 6b22c6147d..d232944593 100644
--- a/libmpdemux/mf.c
+++ b/libmpdemux/mf.c
@@ -25,7 +25,8 @@
#include <errno.h>
#include <limits.h>
#include <sys/types.h>
-#include <sys/stat.h>
+
+#include "osdep/io.h"
#include "config.h"
@@ -38,6 +39,7 @@
#include "mp_msg.h"
#include "stream/stream.h"
+#include "path.h"
#include "mf.h"
@@ -49,7 +51,6 @@ char * mf_type = NULL; //"jpg";
mf_t* open_mf(char * filename){
#if defined(HAVE_GLOB) || defined(__MINGW32__)
glob_t gg;
- struct stat fs;
int i;
char * fname;
mf_t * mf;
@@ -63,13 +64,13 @@ mf_t* open_mf(char * filename){
FILE *lst_f=fopen(filename + 1,"r");
if ( lst_f )
{
- fname=malloc(PATH_MAX);
- while ( fgets( fname,PATH_MAX,lst_f ) )
+ fname=malloc(MP_PATH_MAX);
+ while ( fgets( fname,MP_PATH_MAX,lst_f ) )
{
/* remove spaces from end of fname */
char *t=fname + strlen( fname ) - 1;
while ( t > fname && isspace( *t ) ) *(t--)=0;
- if ( stat( fname,&fs ) )
+ if ( !mp_path_exists( fname ) )
{
mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname );
}
@@ -94,7 +95,7 @@ mf_t* open_mf(char * filename){
while ( ( fname=strsep( &filename,"," ) ) )
{
- if ( stat( fname,&fs ) )
+ if ( !mp_path_exists( fname ) )
{
mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname );
}
@@ -130,8 +131,8 @@ mf_t* open_mf(char * filename){
for( i=0;i < gg.gl_pathc;i++ )
{
- stat( gg.gl_pathv[i],&fs );
- if( S_ISDIR( fs.st_mode ) ) continue;
+ if (mp_path_isdir(gg.gl_pathv[i]))
+ continue;
mf->names[i]=strdup( gg.gl_pathv[i] );
// mp_msg( MSGT_STREAM,MSGL_DBG2,"[mf] added file %d.: %s\n",i,mf->names[i] );
}
@@ -144,7 +145,7 @@ mf_t* open_mf(char * filename){
while ( error_count < 5 )
{
sprintf( fname,filename,count++ );
- if ( stat( fname,&fs ) )
+ if ( !mp_path_exists( fname ) )
{
error_count++;
mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname );
diff --git a/libvo/vo_jpeg.c b/libvo/vo_jpeg.c
index 15f29a293a..efa0381086 100644
--- a/libvo/vo_jpeg.c
+++ b/libvo/vo_jpeg.c
@@ -45,6 +45,7 @@
#include "video_out.h"
#include "video_out_internal.h"
#include "mplayer.h" /* for exit_player_bad() */
+#include "osdep/io.h"
/* ------------------------------------------------------------------------- */
@@ -107,15 +108,11 @@ static int framenum = 0;
static void jpeg_mkdir(const char *buf, int verbose) {
struct stat stat_p;
-#ifndef __MINGW32__
if ( mkdir(buf, 0755) < 0 ) {
-#else
- if ( mkdir(buf) < 0 ) {
-#endif
switch (errno) { /* use switch in case other errors need to be caught
and handled in the future */
case EEXIST:
- if ( stat(buf, &stat_p ) < 0 ) {
+ if ( mp_stat(buf, &stat_p ) < 0 ) {
mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name,
_("This error has occurred"), strerror(errno) );
mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name,
diff --git a/libvo/vo_pnm.c b/libvo/vo_pnm.c
index 9593860412..5345eaa122 100644
--- a/libvo/vo_pnm.c
+++ b/libvo/vo_pnm.c
@@ -40,6 +40,7 @@
#include "video_out.h"
#include "video_out_internal.h"
#include "mplayer.h" /* for exit_player_bad() */
+#include "osdep/io.h"
/* ------------------------------------------------------------------------- */
@@ -199,16 +200,11 @@ static int preinit(const char *arg)
static void pnm_mkdir(char *buf, int verbose) {
struct stat stat_p;
-/* Silly MING32 bug workaround */
-#ifndef __MINGW32__
if ( mkdir(buf, 0755) < 0 ) {
-#else
- if ( mkdir(buf) < 0 ) {
-#endif
switch (errno) { /* use switch in case other errors need to be caught
and handled in the future */
case EEXIST:
- if ( stat(buf, &stat_p ) < 0 ) {
+ if ( mp_stat(buf, &stat_p ) < 0 ) {
mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name,
_("This error has occurred"), strerror(errno) );
mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name,
diff --git a/mplayer.c b/mplayer.c
index cdcd1d645e..f8b24a1285 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -27,6 +27,8 @@
#include "config.h"
#include "talloc.h"
+#include "osdep/io.h"
+
#if defined(__MINGW32__) || defined(__CYGWIN__)
#include <windows.h>
#endif
@@ -875,11 +877,7 @@ static void parse_cfgfiles(struct MPContext *mpctx, m_config_t *conf)
if ((conffile = get_path("")) == NULL)
mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "Cannot find HOME directory.\n");
else {
-#ifdef __MINGW32__
- mkdir(conffile);
-#else
mkdir(conffile, 0777);
-#endif
free(conffile);
if ((conffile = get_path("config")) == NULL)
mp_tmsg(MSGT_CPLAYER, MSGL_ERR, "get_path(\"config\") problem\n");
@@ -968,8 +966,7 @@ static void load_per_output_config(m_config_t *conf, char *cfg, char *out)
*/
static int try_load_config(m_config_t *conf, const char *file)
{
- struct stat st;
- if (stat(file, &st))
+ if (!mp_path_exists(file))
return 0;
mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "Loading config '%s'\n", file);
m_config_parse_config_file(conf, file);
@@ -979,10 +976,10 @@ static int try_load_config(m_config_t *conf, const char *file)
static void load_per_file_config(m_config_t *conf, const char * const file)
{
char *confpath;
- char cfg[PATH_MAX];
+ char cfg[MP_PATH_MAX];
const char *name;
- if (strlen(file) > PATH_MAX - 14) {
+ if (strlen(file) > MP_PATH_MAX - 14) {
mp_msg(MSGT_CPLAYER, MSGL_WARN, "Filename is too long, "
"can not load file or directory specific config files\n");
return;
@@ -991,7 +988,7 @@ static void load_per_file_config(m_config_t *conf, const char * const file)
name = mp_basename(cfg);
if (use_filedir_conf) {
- char dircfg[PATH_MAX];
+ char dircfg[MP_PATH_MAX];
strcpy(dircfg, cfg);
strcpy(dircfg + (name - cfg), "mplayer.conf");
try_load_config(conf, dircfg);
@@ -3974,6 +3971,10 @@ int main(int argc, char *argv[])
|| !strcmp(argv[1], "--leak-report")))
talloc_enable_leak_report();
+#ifdef __MINGW32__
+ mp_get_converted_argv(&argc, &argv);
+#endif
+
char *mem_ptr;
// movie info:
diff --git a/osdep/io.c b/osdep/io.c
new file mode 100644
index 0000000000..88433184f4
--- /dev/null
+++ b/osdep/io.c
@@ -0,0 +1,185 @@
+/*
+ * unicode/utf-8 I/O helpers and wrappers for Windows
+ *
+ * This file is part of mplayer2.
+ * Contains parts based on libav code (http://libav.org).
+ *
+ * mplayer2 is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * mplayer2 is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with mplayer2. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef _WIN32
+
+#include <windows.h>
+#include <wchar.h>
+#include <stdio.h>
+#include <stddef.h>
+
+#include "osdep/io.h"
+#include "talloc.h"
+
+//copied and modified from libav
+//http://git.libav.org/?p=libav.git;a=blob;f=libavformat/os_support.c;h=a0fcd6c9ba2be4b0dbcc476f6c53587345cc1152;hb=HEADl30
+
+wchar_t *mp_from_utf8(void *talloc_ctx, const char *s)
+{
+ int count = MultiByteToWideChar(CP_UTF8, 0, s, -1, NULL, 0);
+ if (count <= 0)
+ abort();
+ wchar_t *ret = talloc_array(talloc_ctx, wchar_t, count);
+ MultiByteToWideChar(CP_UTF8, 0, s, -1, ret, count);
+ return ret;
+}
+
+char *mp_to_utf8(void *talloc_ctx, const wchar_t *s)
+{
+ int count = WideCharToMultiByte(CP_UTF8, 0, s, -1, NULL, 0, NULL, NULL);
+ if (count <= 0)
+ abort();
+ char *ret = talloc_array(talloc_ctx, char, count);
+ WideCharToMultiByte(CP_UTF8, 0, s, -1, ret, count, NULL, NULL);
+ return ret;
+}
+
+#endif // _WIN32
+
+#ifdef __MINGW32__
+
+#include <io.h>
+#include <fcntl.h>
+
+//http://git.libav.org/?p=libav.git;a=blob;f=cmdutils.c;h=ade3f10ce2fc030e32e375a85fbd06c26d43a433#l161
+
+static char** win32_argv_utf8;
+static int win32_argc;
+
+void mp_get_converted_argv(int *argc, char ***argv)
+{
+ if (!win32_argv_utf8) {
+ win32_argc = 0;
+ wchar_t **argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
+ if (win32_argc <= 0 || !argv_w)
+ return;
+
+ win32_argv_utf8 = talloc_zero_array(NULL, char*, win32_argc + 1);
+
+ for (int i = 0; i < win32_argc; i++) {
+ win32_argv_utf8[i] = mp_to_utf8(NULL, argv_w[i]);
+ }
+
+ LocalFree(argv_w);
+ }
+
+ *argc = win32_argc;
+ *argv = win32_argv_utf8;
+}
+
+int mp_stat(const char *path, struct stat *buf)
+{
+ wchar_t *wpath = mp_from_utf8(NULL, path);
+ int res = _wstat64(wpath, buf);
+ talloc_free(wpath);
+ return res;
+}
+
+
+int mp_open(const char *filename, int oflag, ...)
+{
+ int mode = 0;
+ if (oflag & _O_CREAT) {
+ va_list va;
+ va_start(va, oflag);
+ mode = va_arg(va, int);
+ va_end(va);
+ }
+ wchar_t *wpath = mp_from_utf8(NULL, filename);
+ int res = _wopen(wpath, oflag, mode);
+ talloc_free(wpath);
+ return res;
+}
+
+int mp_creat(const char *filename, int mode)
+{
+ return open(filename, O_CREAT|O_WRONLY|O_TRUNC, mode);
+}
+
+FILE *mp_fopen(const char *filename, const char *mode)
+{
+ wchar_t *wpath = mp_from_utf8(NULL, filename);
+ wchar_t *wmode = mp_from_utf8(wpath, mode);
+ FILE *res = _wfopen(wpath, wmode);
+ talloc_free(wpath);
+ return res;
+}
+
+struct mp_dir {
+ DIR crap; // must be first member
+ _WDIR *wdir;
+ union {
+ struct dirent dirent;
+ // dirent has space only for FILENAME_MAX bytes. _wdirent has space for
+ // FILENAME_MAX wchar_t, which might end up bigger as UTF-8 in some
+ // cases. Guarantee we can always hold _wdirent.d_name converted to
+ // UTF-8 (see MP_PATH_MAX).
+ // This works because dirent.d_name is the last member of dirent.
+ char space[MP_PATH_MAX];
+ };
+};
+
+DIR* mp_opendir(const char *path)
+{
+ wchar_t *wpath = mp_from_utf8(NULL, path);
+ _WDIR *wdir = _wopendir(wpath);
+ talloc_free(wpath);
+ if (!wdir)
+ return NULL;
+ struct mp_dir *mpdir = talloc(NULL, struct mp_dir);
+ // DIR is supposed to be opaque, but unfortunately the MinGW headers still
+ // define it. Make sure nobody tries to use it.
+ memset(&mpdir->crap, 0xCD, sizeof(mpdir->crap));
+ mpdir->wdir = wdir;
+ return (DIR*)mpdir;
+}
+
+struct dirent* mp_readdir(DIR *dir)
+{
+ struct mp_dir *mpdir = (struct mp_dir*)dir;
+ struct _wdirent *wdirent = _wreaddir(mpdir->wdir);
+ if (!wdirent)
+ return NULL;
+ size_t buffersize = sizeof(mpdir->space) - offsetof(struct dirent, d_name);
+ WideCharToMultiByte(CP_UTF8, 0, wdirent->d_name, -1, mpdir->dirent.d_name,
+ buffersize, NULL, NULL);
+ mpdir->dirent.d_ino = 0;
+ mpdir->dirent.d_reclen = 0;
+ mpdir->dirent.d_namlen = strlen(mpdir->dirent.d_name);
+ return &mpdir->dirent;
+}
+
+int mp_closedir(DIR *dir)
+{
+ struct mp_dir *mpdir = (struct mp_dir*)dir;
+ int res = _wclosedir(mpdir->wdir);
+ talloc_free(mpdir);
+ return res;
+}
+
+int mp_mkdir(const char *path, int mode)
+{
+ wchar_t *wpath = mp_from_utf8(NULL, path);
+ int res = _wmkdir(wpath);
+ talloc_free(wpath);
+ return res;
+}
+
+#endif // __MINGW32__
diff --git a/osdep/io.h b/osdep/io.h
new file mode 100644
index 0000000000..514030afca
--- /dev/null
+++ b/osdep/io.h
@@ -0,0 +1,76 @@
+/*
+ * unicode/utf-8 I/O helpers and wrappers for Windows
+ *
+ * This file is part of mplayer2.
+ *
+ * mplayer2 is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * mplayer2 is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with mplayer2. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MPLAYER_OSDEP_IO
+#define MPLAYER_OSDEP_IO
+
+#include <limits.h>
+
+#ifdef _WIN32
+#include <wchar.h>
+wchar_t *mp_from_utf8(void *talloc_ctx, const char *s);
+char *mp_to_utf8(void *talloc_ctx, const wchar_t *s);
+#endif
+
+#ifdef __MINGW32__
+
+#include <stdio.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+// Windows' MAX_PATH/PATH_MAX/FILENAME_MAX is fixed to 260, but this limit
+// applies to unicode paths encoded with wchar_t (2 bytes on Windows). The UTF-8
+// version could end up bigger in memory. In the worst case each wchar_t is
+// encoded to 3 bytes in UTF-8, so in the worst case we have:
+// wcslen(wpath) <= strlen(utf8path) * 3
+// Thus we need MP_PATH_MAX as the UTF-8/char version of PATH_MAX.
+#define MP_PATH_MAX (FILENAME_MAX * 3)
+
+void mp_get_converted_argv(int *argc, char ***argv);
+
+int mp_stat(const char *path, struct stat *buf);
+int mp_open(const char *filename, int oflag, ...);
+int mp_creat(const char *filename, int mode);
+FILE *mp_fopen(const char *filename, const char *mode);
+DIR *mp_opendir(const char *path);
+struct dirent *mp_readdir(DIR *dir);
+int mp_closedir(DIR *dir);
+int mp_mkdir(const char *path, int mode);
+
+// NOTE: Stat is not overridden with mp_stat, because MinGW-w64 defines it as
+// macro.
+
+#define open(...) mp_open(__VA_ARGS__)
+#define creat(...) mp_creat(__VA_ARGS__)
+#define fopen(...) mp_fopen(__VA_ARGS__)
+#define opendir(...) mp_opendir(__VA_ARGS__)
+#define readdir(...) mp_readdir(__VA_ARGS__)
+#define closedir(...) mp_closedir(__VA_ARGS__)
+#define mkdir(...) mp_mkdir(__VA_ARGS__)
+
+#else /* __MINGW32__ */
+
+#define MP_PATH_MAX PATH_MAX
+
+#define mp_stat(...) stat(__VA_ARGS__)
+
+#endif /* __MINGW32__ */
+
+#endif
diff --git a/parser-cfg.c b/parser-cfg.c
index e2c5d208e2..f6a4c67d3a 100644
--- a/parser-cfg.c
+++ b/parser-cfg.c
@@ -25,6 +25,8 @@
#include <ctype.h>
#include <assert.h>
+#include "osdep/io.h"
+
#include "parser-cfg.h"
#include "mp_msg.h"
#include "m_option.h"
diff --git a/path.c b/path.c
index b99d694df5..b6b87d4e9b 100644
--- a/path.c
+++ b/path.c
@@ -27,14 +27,15 @@
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
#include "config.h"
#include "mp_msg.h"
#include "path.h"
#ifdef CONFIG_MACOSX_BUNDLE
#include <CoreFoundation/CoreFoundation.h>
-#include <sys/types.h>
-#include <sys/stat.h>
#include <unistd.h>
#elif defined(__MINGW32__)
#include <windows.h>
@@ -46,6 +47,7 @@
#include "talloc.h"
#include "osdep/osdep.h"
+#include "osdep/io.h"
char *get_path(const char *filename){
char *homedir;
@@ -232,3 +234,15 @@ char *mp_path_join(void *talloc_ctx, struct bstr p1, struct bstr p2)
return talloc_asprintf(talloc_ctx, "%.*s%s%.*s", BSTR_P(p1),
have_separator ? "" : "/", BSTR_P(p2));
}
+
+bool mp_path_exists(const char *path)
+{
+ struct stat st;
+ return mp_stat(path, &st) == 0;
+}
+
+bool mp_path_isdir(const char *path)
+{
+ struct stat st;
+ return mp_stat(path, &st) == 0 && S_ISDIR(st.st_mode);
+}
diff --git a/path.h b/path.h
index ffa052d680..9293852e2d 100644
--- a/path.h
+++ b/path.h
@@ -21,6 +21,7 @@
#ifndef MPLAYER_PATH_H
#define MPLAYER_PATH_H
+#include <stdbool.h>
#include "bstr.h"
extern char *codec_path;
@@ -44,4 +45,7 @@ struct bstr mp_dirname(const char *path);
*/
char *mp_path_join(void *talloc_ctx, struct bstr p1, struct bstr p2);
+bool mp_path_exists(const char *path);
+bool mp_path_isdir(const char *path);
+
#endif /* MPLAYER_PATH_H */
diff --git a/screenshot.c b/screenshot.c
index 597a36afed..af1c5c1da2 100644
--- a/screenshot.c
+++ b/screenshot.c
@@ -21,10 +21,6 @@
#include <string.h>
#include <inttypes.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
#include <libswscale/swscale.h>
#include <libavcodec/avcodec.h>
@@ -33,6 +29,7 @@
#include "screenshot.h"
#include "mp_core.h"
#include "mp_msg.h"
+#include "path.h"
#include "libmpcodecs/img_format.h"
#include "libmpcodecs/mp_image.h"
#include "libmpcodecs/dec_video.h"
@@ -130,11 +127,7 @@ error_exit:
static int fexists(char *fname)
{
- struct stat dummy;
- if (stat(fname, &dummy) == 0)
- return 1;
- else
- return 0;
+ return mp_path_exists(fname);
}
static void gen_fname(screenshot_ctx *ctx)
diff --git a/stream/cookies.c b/stream/cookies.c
index 3b266a5ca2..e50274a248 100644
--- a/stream/cookies.c
+++ b/stream/cookies.c
@@ -31,6 +31,8 @@
#include <inttypes.h>
#include <limits.h>
+#include "osdep/io.h"
+
#include "cookies.h"
#include "http.h"
#include "mp_msg.h"
diff --git a/stream/stream_cddb.c b/stream/stream_cddb.c
index afc512e5b7..aab557ab86 100644
--- a/stream/stream_cddb.c
+++ b/stream/stream_cddb.c
@@ -36,11 +36,8 @@
#include <unistd.h>
#include <string.h>
#include <limits.h>
+#include "osdep/io.h"
#if defined(__MINGW32__) || defined(__CYGWIN__)
-#ifdef __MINGW32__
-#include <path.h>
-#define mkdir(a,b) mkdir(a)
-#endif
#include <windows.h>
#if HAVE_WINSOCK2_H
#include <winsock2.h>
@@ -53,6 +50,7 @@
#include <sys/stat.h>
#include "mp_msg.h"
+#include "path.h"
#if defined(__linux__)
#include <linux/cdrom.h>
@@ -472,7 +470,6 @@ static int cddb_read_cache(cddb_data_t *cddb_data)
static int cddb_write_cache(cddb_data_t *cddb_data)
{
// We have the file, save it for cache.
- struct stat file_stat;
char file_name[100];
int file_fd, ret;
int wrote = 0;
@@ -481,8 +478,7 @@ static int cddb_write_cache(cddb_data_t *cddb_data)
return -1;
// Check if the CDDB cache dir exist
- ret = stat(cddb_data->cache_dir, &file_stat);
- if (ret < 0) {
+ if (!mp_path_exists(cddb_data->cache_dir)) {
// Directory not present, create it.
ret = mkdir(cddb_data->cache_dir, 0755);
#ifdef __MINGW32__
diff --git a/stream/stream_file.c b/stream/stream_file.c
index 6d436cf6f5..e9bb3eb03a 100644
--- a/stream/stream_file.c
+++ b/stream/stream_file.c
@@ -24,6 +24,8 @@
#include <fcntl.h>
#include <unistd.h>
+#include "osdep/io.h"
+
#include "mp_msg.h"
#include "stream.h"
#include "m_option.h"
diff --git a/sub/find_subfiles.c b/sub/find_subfiles.c
index 3de8014ce1..6af599183f 100644
--- a/sub/find_subfiles.c
+++ b/sub/find_subfiles.c
@@ -4,6 +4,8 @@
#include <ctype.h>
#include <assert.h>
+#include "osdep/io.h"
+
#include "mp_msg.h"
#include "options.h"
#include "path.h"
diff --git a/sub/font_load.c b/sub/font_load.c
index 7bf7775501..d8f9eafe34 100644
--- a/sub/font_load.c
+++ b/sub/font_load.c
@@ -21,9 +21,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
+
+#include "osdep/io.h"
#include "font_load.h"
#include "mp_msg.h"
@@ -72,7 +71,6 @@ unsigned char sor2[1024];
font_desc_t *desc;
FILE *f = NULL;
char *dn;
-//struct stat fstate;
char section[64];
int i,j;
int chardb=0;
@@ -93,10 +91,6 @@ if ((dn = malloc(i+1))){
desc->fpath = dn; // search in the same dir as fonts.desc
-// desc->fpath=get_path("font/");
-// if (stat(desc->fpath, &fstate)!=0) desc->fpath=DATADIR"/font";
-
-
// set up some defaults, and erase table
diff --git a/timeline/tl_matroska.c b/timeline/tl_matroska.c
index d378cf3aa4..00fd6b7088 100644
--- a/timeline/tl_matroska.c
+++ b/timeline/tl_matroska.c
@@ -23,6 +23,8 @@
#include <dirent.h>
#include <libavutil/common.h>
+#include "osdep/io.h"
+
#include "talloc.h"
#include "mp_core.h"