Skip to content

Commit a124411

Browse files
wm4Uoti Urpala
wm4
authored and
Uoti Urpala
committed
windows support: unicode filenames
Windows uses a legacy codepage for char* / runtime functions accepting char *. Using UTF-8 as the codepage with setlocale() is explicitly forbidden. Work this around by overriding the MSVCRT functions with wrapper macros, that assume UTF-8 and use "proper" API calls like _wopen etc. to deal with unicode filenames. All code that uses standard functions that take or return filenames must now include osdep/io.h. stat() can't be overridden, because MinGW-w64 itself defines "stat" as a macro. Change code to use use mp_stat() instead. This is not perfectly clean, but still somewhat sane, and much better than littering the rest of the mplayer code with MinGW specific hacks. It's also a bit fragile, but that's actually little different from the previous situation. Also, MinGW is unlikely to ever include a nice way of dealing with this.
1 parent 24be34f commit a124411

20 files changed

+342
-66
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ SRCS_COMMON = asxparser.c \
403403
libmpdemux/yuv4mpeg_ratio.c \
404404
libvo/osd.c \
405405
osdep/numcores.c \
406+
osdep/io.c \
406407
osdep/$(GETCH) \
407408
osdep/$(TIMER) \
408409
stream/open.c \

input/input.c

+10-5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include <ctype.h>
3232
#include <assert.h>
3333

34+
#include "osdep/io.h"
35+
3436
#include "input.h"
3537
#include "mp_fifo.h"
3638
#include "keycodes.h"
@@ -1776,13 +1778,16 @@ struct input_ctx *mp_input_init(struct input_conf *input_conf)
17761778
#endif
17771779

17781780
if (input_conf->in_file) {
1779-
struct stat st;
1780-
int mode = O_RDONLY | O_NONBLOCK;
1781+
int mode = O_RDONLY;
1782+
#ifndef __MINGW32__
17811783
// Use RDWR for FIFOs to ensure they stay open over multiple accesses.
1782-
// Note that on Windows stat may fail for named pipes,
1783-
// but due to how the API works, using RDONLY should be ok.
1784+
// Note that on Windows due to how the API works, using RDONLY should
1785+
// be ok.
1786+
struct stat st;
17841787
if (stat(input_conf->in_file, &st) == 0 && S_ISFIFO(st.st_mode))
1785-
mode = O_RDWR | O_NONBLOCK;
1788+
mode = O_RDWR;
1789+
mode |= O_NONBLOCK;
1790+
#endif
17861791
int in_file_fd = open(input_conf->in_file, mode);
17871792
if (in_file_fd >= 0)
17881793
mp_input_add_cmd_fd(ictx, in_file_fd, 1, NULL, close);

libmpcodecs/vf_remove_logo.c

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686
#include <ctype.h>
8787
#include <inttypes.h>
8888

89+
#include "osdep/io.h"
90+
8991
#include "config.h"
9092
#include "mp_msg.h"
9193
#include "libvo/fastmemcpy.h"

libmpdemux/demux_mf.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <sys/stat.h>
2424
#include <unistd.h>
2525

26+
#include "osdep/io.h"
27+
2628
#include "talloc.h"
2729
#include "config.h"
2830
#include "mp_msg.h"
@@ -49,20 +51,19 @@ static void demux_seek_mf(demuxer_t *demuxer,float rel_seek_secs,float audio_del
4951
// 1 = successfully read a packet
5052
static int demux_mf_fill_buffer(demuxer_t *demuxer, demux_stream_t *ds){
5153
mf_t * mf;
52-
struct stat fs;
5354
FILE * f;
5455

5556
mf=(mf_t*)demuxer->priv;
5657
if ( mf->curr_frame >= mf->nr_of_files ) return 0;
5758

58-
stat( mf->names[mf->curr_frame],&fs );
59-
// printf( "[demux_mf] frame: %d (%s,%d)\n",mf->curr_frame,mf->names[mf->curr_frame],fs.st_size );
60-
6159
if ( !( f=fopen( mf->names[mf->curr_frame],"rb" ) ) ) return 0;
6260
{
6361
sh_video_t * sh_video = demuxer->video->sh;
64-
demux_packet_t * dp = new_demux_packet( fs.st_size );
65-
if ( !fread( dp->buffer,fs.st_size,1,f ) ) return 0;
62+
fseek(f, 0, SEEK_END);
63+
long file_size = ftell(f);
64+
fseek(f, 0, SEEK_SET);
65+
demux_packet_t * dp = new_demux_packet( file_size );
66+
if ( !fread( dp->buffer,file_size,1,f ) ) return 0;
6667
dp->pts=mf->curr_frame / sh_video->fps;
6768
dp->pos=mf->curr_frame;
6869
dp->flags=0;

libmpdemux/mf.c

+10-9
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
#include <errno.h>
2626
#include <limits.h>
2727
#include <sys/types.h>
28-
#include <sys/stat.h>
28+
29+
#include "osdep/io.h"
2930

3031
#include "config.h"
3132

@@ -38,6 +39,7 @@
3839

3940
#include "mp_msg.h"
4041
#include "stream/stream.h"
42+
#include "path.h"
4143

4244
#include "mf.h"
4345

@@ -49,7 +51,6 @@ char * mf_type = NULL; //"jpg";
4951
mf_t* open_mf(char * filename){
5052
#if defined(HAVE_GLOB) || defined(__MINGW32__)
5153
glob_t gg;
52-
struct stat fs;
5354
int i;
5455
char * fname;
5556
mf_t * mf;
@@ -63,13 +64,13 @@ mf_t* open_mf(char * filename){
6364
FILE *lst_f=fopen(filename + 1,"r");
6465
if ( lst_f )
6566
{
66-
fname=malloc(PATH_MAX);
67-
while ( fgets( fname,PATH_MAX,lst_f ) )
67+
fname=malloc(MP_PATH_MAX);
68+
while ( fgets( fname,MP_PATH_MAX,lst_f ) )
6869
{
6970
/* remove spaces from end of fname */
7071
char *t=fname + strlen( fname ) - 1;
7172
while ( t > fname && isspace( *t ) ) *(t--)=0;
72-
if ( stat( fname,&fs ) )
73+
if ( !mp_path_exists( fname ) )
7374
{
7475
mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname );
7576
}
@@ -94,7 +95,7 @@ mf_t* open_mf(char * filename){
9495

9596
while ( ( fname=strsep( &filename,"," ) ) )
9697
{
97-
if ( stat( fname,&fs ) )
98+
if ( !mp_path_exists( fname ) )
9899
{
99100
mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname );
100101
}
@@ -130,8 +131,8 @@ mf_t* open_mf(char * filename){
130131

131132
for( i=0;i < gg.gl_pathc;i++ )
132133
{
133-
stat( gg.gl_pathv[i],&fs );
134-
if( S_ISDIR( fs.st_mode ) ) continue;
134+
if (mp_path_isdir(gg.gl_pathv[i]))
135+
continue;
135136
mf->names[i]=strdup( gg.gl_pathv[i] );
136137
// mp_msg( MSGT_STREAM,MSGL_DBG2,"[mf] added file %d.: %s\n",i,mf->names[i] );
137138
}
@@ -144,7 +145,7 @@ mf_t* open_mf(char * filename){
144145
while ( error_count < 5 )
145146
{
146147
sprintf( fname,filename,count++ );
147-
if ( stat( fname,&fs ) )
148+
if ( !mp_path_exists( fname ) )
148149
{
149150
error_count++;
150151
mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname );

libvo/vo_jpeg.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "video_out.h"
4646
#include "video_out_internal.h"
4747
#include "mplayer.h" /* for exit_player_bad() */
48+
#include "osdep/io.h"
4849

4950
/* ------------------------------------------------------------------------- */
5051

@@ -107,15 +108,11 @@ static int framenum = 0;
107108
static void jpeg_mkdir(const char *buf, int verbose) {
108109
struct stat stat_p;
109110

110-
#ifndef __MINGW32__
111111
if ( mkdir(buf, 0755) < 0 ) {
112-
#else
113-
if ( mkdir(buf) < 0 ) {
114-
#endif
115112
switch (errno) { /* use switch in case other errors need to be caught
116113
and handled in the future */
117114
case EEXIST:
118-
if ( stat(buf, &stat_p ) < 0 ) {
115+
if ( mp_stat(buf, &stat_p ) < 0 ) {
119116
mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name,
120117
_("This error has occurred"), strerror(errno) );
121118
mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name,

libvo/vo_pnm.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "video_out.h"
4141
#include "video_out_internal.h"
4242
#include "mplayer.h" /* for exit_player_bad() */
43+
#include "osdep/io.h"
4344

4445
/* ------------------------------------------------------------------------- */
4546

@@ -199,16 +200,11 @@ static int preinit(const char *arg)
199200
static void pnm_mkdir(char *buf, int verbose) {
200201
struct stat stat_p;
201202

202-
/* Silly MING32 bug workaround */
203-
#ifndef __MINGW32__
204203
if ( mkdir(buf, 0755) < 0 ) {
205-
#else
206-
if ( mkdir(buf) < 0 ) {
207-
#endif
208204
switch (errno) { /* use switch in case other errors need to be caught
209205
and handled in the future */
210206
case EEXIST:
211-
if ( stat(buf, &stat_p ) < 0 ) {
207+
if ( mp_stat(buf, &stat_p ) < 0 ) {
212208
mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name,
213209
_("This error has occurred"), strerror(errno) );
214210
mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name,

mplayer.c

+10-9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include "config.h"
2828
#include "talloc.h"
2929

30+
#include "osdep/io.h"
31+
3032
#if defined(__MINGW32__) || defined(__CYGWIN__)
3133
#include <windows.h>
3234
#endif
@@ -875,11 +877,7 @@ static void parse_cfgfiles(struct MPContext *mpctx, m_config_t *conf)
875877
if ((conffile = get_path("")) == NULL)
876878
mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "Cannot find HOME directory.\n");
877879
else {
878-
#ifdef __MINGW32__
879-
mkdir(conffile);
880-
#else
881880
mkdir(conffile, 0777);
882-
#endif
883881
free(conffile);
884882
if ((conffile = get_path("config")) == NULL)
885883
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)
968966
*/
969967
static int try_load_config(m_config_t *conf, const char *file)
970968
{
971-
struct stat st;
972-
if (stat(file, &st))
969+
if (!mp_path_exists(file))
973970
return 0;
974971
mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "Loading config '%s'\n", file);
975972
m_config_parse_config_file(conf, file);
@@ -979,10 +976,10 @@ static int try_load_config(m_config_t *conf, const char *file)
979976
static void load_per_file_config(m_config_t *conf, const char * const file)
980977
{
981978
char *confpath;
982-
char cfg[PATH_MAX];
979+
char cfg[MP_PATH_MAX];
983980
const char *name;
984981

985-
if (strlen(file) > PATH_MAX - 14) {
982+
if (strlen(file) > MP_PATH_MAX - 14) {
986983
mp_msg(MSGT_CPLAYER, MSGL_WARN, "Filename is too long, "
987984
"can not load file or directory specific config files\n");
988985
return;
@@ -991,7 +988,7 @@ static void load_per_file_config(m_config_t *conf, const char * const file)
991988

992989
name = mp_basename(cfg);
993990
if (use_filedir_conf) {
994-
char dircfg[PATH_MAX];
991+
char dircfg[MP_PATH_MAX];
995992
strcpy(dircfg, cfg);
996993
strcpy(dircfg + (name - cfg), "mplayer.conf");
997994
try_load_config(conf, dircfg);
@@ -3974,6 +3971,10 @@ int main(int argc, char *argv[])
39743971
|| !strcmp(argv[1], "--leak-report")))
39753972
talloc_enable_leak_report();
39763973

3974+
#ifdef __MINGW32__
3975+
mp_get_converted_argv(&argc, &argv);
3976+
#endif
3977+
39773978
char *mem_ptr;
39783979

39793980
// movie info:

0 commit comments

Comments
 (0)