Skip to content

Commit 224674a

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 7931d54 + 6634e6c commit 224674a

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 = CreateFileA("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) {
@@ -2357,13 +2357,19 @@ struct passwd *getpwuid(int uid)
23572357
static unsigned initialized;
23582358
static char user_name[100];
23592359
static struct passwd *p;
2360+
wchar_t buf[100];
23602361
DWORD len;
23612362

23622363
if (initialized)
23632364
return p;
23642365

2365-
len = sizeof(user_name);
2366-
if (!GetUserNameA(user_name, &len)) {
2366+
len = sizeof(buf);
2367+
if (!GetUserNameW(buf, &len)) {
2368+
initialized = 1;
2369+
return NULL;
2370+
}
2371+
2372+
if (xwcstoutf(user_name, buf, sizeof(user_name)) < 0) {
23672373
initialized = 1;
23682374
return NULL;
23692375
}

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 (GetModuleHandleA ("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 = CreateNamedPipeA(name, PIPE_ACCESS_OUTBOUND,
631+
if (swprintf(name, sizeof(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 = CreateFileA(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)