Skip to content

Commit 8b16818

Browse files
committed
Merge branch 'ansi-unicode'
This patch series teaches Git's source code to use the Unicode variants of the Win32 API functions explicitly, which makes things less magical and more robust. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 191ab97 + d652f62 commit 8b16818

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

compat/mingw.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,7 +1693,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
16931693
do_unset_environment_variables();
16941694

16951695
/* Determine whether or not we are associated to a console */
1696-
cons = CreateFile("CONOUT$", GENERIC_WRITE,
1696+
cons = CreateFileW(L"CONOUT$", GENERIC_WRITE,
16971697
FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
16981698
FILE_ATTRIBUTE_NORMAL, NULL);
16991699
if (cons == INVALID_HANDLE_VALUE) {
@@ -2366,13 +2366,19 @@ struct passwd *getpwuid(int uid)
23662366
static unsigned initialized;
23672367
static char user_name[100];
23682368
static struct passwd *p;
2369+
wchar_t buf[100];
23692370
DWORD len;
23702371

23712372
if (initialized)
23722373
return p;
23732374

2374-
len = sizeof(user_name);
2375-
if (!GetUserName(user_name, &len)) {
2375+
len = sizeof(buf);
2376+
if (!GetUserNameW(buf, &len)) {
2377+
initialized = 1;
2378+
return NULL;
2379+
}
2380+
2381+
if (xwcstoutf(user_name, buf, sizeof(user_name)) < 0) {
23762382
initialized = 1;
23772383
return NULL;
23782384
}

compat/poll/poll.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ win32_compute_revents (HANDLE h, int *p_sought)
150150
if (!once_only)
151151
{
152152
NtQueryInformationFile = (PNtQueryInformationFile)(void (*)(void))
153-
GetProcAddress (GetModuleHandle ("ntdll.dll"),
153+
GetProcAddress (GetModuleHandleW (L"ntdll.dll"),
154154
"NtQueryInformationFile");
155155
once_only = TRUE;
156156
}

compat/winansi.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ int winansi_isatty(int fd)
608608
void winansi_init(void)
609609
{
610610
int con1, con2;
611-
char name[32];
611+
wchar_t name[32];
612612

613613
/* check if either stdout or stderr is a console output screen buffer */
614614
con1 = is_console(1);
@@ -628,13 +628,15 @@ void winansi_init(void)
628628
}
629629

630630
/* create a named pipe to communicate with the console thread */
631-
xsnprintf(name, sizeof(name), "\\\\.\\pipe\\winansi%lu", GetCurrentProcessId());
632-
hwrite = CreateNamedPipe(name, PIPE_ACCESS_OUTBOUND,
631+
if (swprintf(name, ARRAY_SIZE(name) - 1, L"\\\\.\\pipe\\winansi%lu",
632+
GetCurrentProcessId()) < 0)
633+
die("Could not initialize winansi pipe name");
634+
hwrite = CreateNamedPipeW(name, PIPE_ACCESS_OUTBOUND,
633635
PIPE_TYPE_BYTE | PIPE_WAIT, 1, BUFFER_SIZE, 0, 0, NULL);
634636
if (hwrite == INVALID_HANDLE_VALUE)
635637
die_lasterr("CreateNamedPipe failed");
636638

637-
hread = CreateFile(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
639+
hread = CreateFileW(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
638640
if (hread == INVALID_HANDLE_VALUE)
639641
die_lasterr("CreateFile for named pipe failed");
640642

0 commit comments

Comments
 (0)