Skip to content

Commit 53034fe

Browse files
committed
pull ps_title behind the logic to support the current codepage
1 parent 525eb35 commit 53034fe

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

sapi/cli/ps_title.c

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "config.w32.h"
4343
#include <windows.h>
4444
#include <process.h>
45+
#include "win32/codepage.h"
4546
#else
4647
#include "php_config.h"
4748
extern char** environ;
@@ -109,8 +110,6 @@ extern char** environ;
109110
static char windows_error_details[64];
110111
static char ps_buffer[MAX_PATH];
111112
static const size_t ps_buffer_size = MAX_PATH;
112-
typedef BOOL (WINAPI *MySetConsoleTitle)(LPCTSTR);
113-
typedef DWORD (WINAPI *MyGetConsoleTitle)(LPTSTR, DWORD);
114113
#elif defined(PS_USE_CLOBBER_ARGV)
115114
static char *ps_buffer; /* will point to argv area */
116115
static size_t ps_buffer_size; /* space determined at run time */
@@ -371,22 +370,13 @@ int set_ps_title(const char* title)
371370

372371
#ifdef PS_USE_WIN32
373372
{
374-
MySetConsoleTitle set_title = NULL;
375-
HMODULE hMod = LoadLibrary("kernel32.dll");
373+
wchar_t *ps_buffer_w = php_win32_cp_any_to_w(ps_buffer);
376374

377-
if (!hMod) {
375+
if (!ps_buffer_w || !SetConsoleTitleW(ps_buffer_w)) {
378376
return PS_TITLE_WINDOWS_ERROR;
379377
}
380378

381-
/* NOTE we don't use _UNICODE*/
382-
set_title = (MySetConsoleTitle)GetProcAddress(hMod, "SetConsoleTitleA");
383-
if (!set_title) {
384-
return PS_TITLE_WINDOWS_ERROR;
385-
}
386-
387-
if (!set_title(ps_buffer)) {
388-
return PS_TITLE_WINDOWS_ERROR;
389-
}
379+
free(ps_buffer_w);
390380
}
391381
#endif /* PS_USE_WIN32 */
392382

@@ -407,22 +397,23 @@ int get_ps_title(int *displen, const char** string)
407397

408398
#ifdef PS_USE_WIN32
409399
{
410-
MyGetConsoleTitle get_title = NULL;
411-
HMODULE hMod = LoadLibrary("kernel32.dll");
400+
wchar_t ps_buffer_w[MAX_PATH];
401+
char *tmp;
412402

413-
if (!hMod) {
403+
if (!(ps_buffer_cur_len = GetConsoleTitleW(ps_buffer_w, (DWORD)sizeof(ps_buffer_w)))) {
414404
return PS_TITLE_WINDOWS_ERROR;
415405
}
416406

417-
/* NOTE we don't use _UNICODE*/
418-
get_title = (MyGetConsoleTitle)GetProcAddress(hMod, "GetConsoleTitleA");
419-
if (!get_title) {
407+
tmp = php_win32_cp_conv_w_to_any(ps_buffer_w, PHP_WIN32_CP_IGNORE_LEN, &ps_buffer_cur_len);
408+
if (!tmp) {
420409
return PS_TITLE_WINDOWS_ERROR;
421410
}
422411

423-
if (!(ps_buffer_cur_len = get_title(ps_buffer, (DWORD)ps_buffer_size))) {
424-
return PS_TITLE_WINDOWS_ERROR;
425-
}
412+
ps_buffer_cur_len = ps_buffer_cur_len > sizeof(ps_buffer)-1 ? sizeof(ps_buffer)-1 : ps_buffer_cur_len;
413+
414+
memmove(ps_buffer, tmp, ps_buffer_size);
415+
ps_buffer[ps_buffer_cur_len] = '\0';
416+
free(tmp);
426417
}
427418
#endif
428419
*displen = (int)ps_buffer_cur_len;

0 commit comments

Comments
 (0)