diff --git a/racket/src/cs/c/boot.c b/racket/src/cs/c/boot.c index dfa8a110d3..13aa0b8e50 100644 --- a/racket/src/cs/c/boot.c +++ b/racket/src/cs/c/boot.c @@ -1,5 +1,8 @@ #ifndef WIN32 # include +#else +# include +# include #endif #include #include @@ -28,6 +31,24 @@ # define BOOT_O_BINARY 0 #endif +#ifdef WIN32 +int boot_open(const char *path, int flags) { + int sz = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0); + wchar_t *w_path = malloc(sz * sizeof(wchar_t)); + + MultiByteToWideChar(CP_UTF8, 0, path, -1, w_path, sz); + + { + int r = _wopen(w_path, flags); + + free(w_path); + return r; + } +} +#else +# define boot_open open +#endif + static ptr Sbytevector(char *s) { iptr len = strlen(s); @@ -121,13 +142,13 @@ void racket_boot(racket_boot_arguments_t *ba) close_fd2 = 1; #endif - fd1 = open(ba->boot1_path, O_RDONLY | BOOT_O_BINARY); + fd1 = boot_open(ba->boot1_path, O_RDONLY | BOOT_O_BINARY); Sregister_boot_file_fd_region("petite", fd1, ba->boot1_offset, ba->boot1_len, close_fd1); if (!close_fd1) fd2 = fd1; else - fd2 = open(ba->boot2_path, O_RDONLY | BOOT_O_BINARY); + fd2 = boot_open(ba->boot2_path, O_RDONLY | BOOT_O_BINARY); Sregister_boot_file_fd_region("scheme", fd2, ba->boot2_offset, ba->boot2_len, close_fd2); # ifdef RACKET_AS_BOOT @@ -137,7 +158,7 @@ void racket_boot(racket_boot_arguments_t *ba) if (!close_fd2) fd3 = fd2; else - fd3 = open(ba->boot3_path, O_RDONLY | BOOT_O_BINARY); + fd3 = boot_open(ba->boot3_path, O_RDONLY | BOOT_O_BINARY); Sregister_boot_file_fd_region("racket", fd3, ba->boot3_offset, ba->boot3_len, 1); } # endif