Skip to content

Commit cae7dcf

Browse files
dschoGit for Windows Build Agent
authored and
Git for Windows Build Agent
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 704216c + d5c6503 commit cae7dcf

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
@@ -1435,7 +1435,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
14351435
do_unset_environment_variables();
14361436

14371437
/* Determine whether or not we are associated to a console */
1438-
cons = CreateFile("CONOUT$", GENERIC_WRITE,
1438+
cons = CreateFileW(L"CONOUT$", GENERIC_WRITE,
14391439
FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
14401440
FILE_ATTRIBUTE_NORMAL, NULL);
14411441
if (cons == INVALID_HANDLE_VALUE) {
@@ -1981,13 +1981,19 @@ struct passwd *getpwuid(int uid)
19811981
static unsigned initialized;
19821982
static char user_name[100];
19831983
static struct passwd *p;
1984+
wchar_t buf[100];
19841985
DWORD len;
19851986

19861987
if (initialized)
19871988
return p;
19881989

1989-
len = sizeof(user_name);
1990-
if (!GetUserName(user_name, &len)) {
1990+
len = sizeof(buf);
1991+
if (!GetUserNameW(buf, &len)) {
1992+
initialized = 1;
1993+
return NULL;
1994+
}
1995+
1996+
if (xwcstoutf(user_name, buf, sizeof(user_name)) < 0) {
19911997
initialized = 1;
19921998
return NULL;
19931999
}

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)
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
@@ -612,7 +612,7 @@ int winansi_isatty(int fd)
612612
void winansi_init(void)
613613
{
614614
int con1, con2;
615-
char name[32];
615+
wchar_t name[32];
616616

617617
/* check if either stdout or stderr is a console output screen buffer */
618618
con1 = is_console(1);
@@ -632,13 +632,15 @@ void winansi_init(void)
632632
}
633633

634634
/* create a named pipe to communicate with the console thread */
635-
xsnprintf(name, sizeof(name), "\\\\.\\pipe\\winansi%lu", GetCurrentProcessId());
636-
hwrite = CreateNamedPipe(name, PIPE_ACCESS_OUTBOUND,
635+
if (swprintf(name, ARRAY_SIZE(name) - 1, L"\\\\.\\pipe\\winansi%lu",
636+
GetCurrentProcessId()) < 0)
637+
die("Could not initialize winansi pipe name");
638+
hwrite = CreateNamedPipeW(name, PIPE_ACCESS_OUTBOUND,
637639
PIPE_TYPE_BYTE | PIPE_WAIT, 1, BUFFER_SIZE, 0, 0, NULL);
638640
if (hwrite == INVALID_HANDLE_VALUE)
639641
die_lasterr("CreateNamedPipe failed");
640642

641-
hread = CreateFile(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
643+
hread = CreateFileW(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
642644
if (hread == INVALID_HANDLE_VALUE)
643645
die_lasterr("CreateFile for named pipe failed");
644646

0 commit comments

Comments
 (0)