windows: fix finding self for boot files

Use a wide-character function instead of an ASCII function
to open the executable. Otherwise, Racket breaks when installed
into a non-ASCII path.
This commit is contained in:
Matthew Flatt 2021-02-16 17:21:19 -07:00
parent f502cf3b4e
commit 616daa2239

View File

@ -1,5 +1,8 @@
#ifndef WIN32
# include <unistd.h>
#else
# include <io.h>
# include <windows.h>
#endif
#include <stdio.h>
#include <fcntl.h>
@ -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