@@ -447,10 +447,17 @@ dispatch_io_create_with_path(dispatch_io_type_t type, const char *path,
447
447
_dispatch_retain (channel );
448
448
dispatch_async (channel -> queue , ^{
449
449
int err = 0 ;
450
+ #if defined(_WIN32 )
451
+ struct _stat st ;
452
+ int wide_len = MultiByteToWideChar (CP_UTF8 , 0 , path , -1 , NULL , 0 );
453
+ WCHAR * wide_path = malloc (wide_len * sizeof (WCHAR ));
454
+ MultiByteToWideChar (CP_UTF8 , 0 , path , -1 , wide_path , wide_len );
455
+ #else
450
456
struct stat st ;
457
+ #endif
451
458
_dispatch_io_syscall_switch_noerr (err ,
452
459
#if defined(_WIN32 )
453
- stat ( path_data -> path , & st ),
460
+ _wstat ( wide_path , & st ),
454
461
#else
455
462
(path_data -> oflag & O_NOFOLLOW ) == O_NOFOLLOW
456
463
#if __APPLE__
@@ -476,7 +483,11 @@ dispatch_io_create_with_path(dispatch_io_type_t type, const char *path,
476
483
* c = 0 ;
477
484
int perr ;
478
485
_dispatch_io_syscall_switch_noerr (perr ,
486
+ #if defined(_WIN32 )
487
+ _wstat (wide_path , & st ),
488
+ #else
479
489
stat (path_data -> path , & st ),
490
+ #endif
480
491
case 0 :
481
492
// Since the parent directory exists, open() will
482
493
// create a regular file after the fd_entry has
@@ -493,6 +504,9 @@ dispatch_io_create_with_path(dispatch_io_type_t type, const char *path,
493
504
}
494
505
break ;
495
506
);
507
+ #if defined(_WIN32 )
508
+ free (wide_path );
509
+ #endif
496
510
channel -> err = err ;
497
511
if (err ) {
498
512
free (path_data );
@@ -1333,9 +1347,14 @@ _dispatch_fd_entry_guarded_open(dispatch_fd_entry_t fd_entry, const char *path,
1333
1347
} else if (oflag & _O_TRUNC ) {
1334
1348
dwCreationDisposition = TRUNCATE_EXISTING ;
1335
1349
}
1336
- return (dispatch_fd_t )CreateFile (path , dwDesiredAccess ,
1350
+ int wide_len = MultiByteToWideChar (CP_UTF8 , 0 , path , -1 , NULL , 0 );
1351
+ WCHAR * wide_path = malloc (wide_len * sizeof (WCHAR ));
1352
+ MultiByteToWideChar (CP_UTF8 , 0 , path , -1 , wide_path , wide_len );
1353
+ dispatch_fd_t fd = (dispatch_fd_t )CreateFileW (wide_path , dwDesiredAccess ,
1337
1354
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , NULL ,
1338
1355
dwCreationDisposition , 0 , NULL );
1356
+ free (wide_path );
1357
+ return fd ;
1339
1358
#else
1340
1359
return open (path , oflag , mode );
1341
1360
#endif
0 commit comments