diff options
-rw-r--r-- | win32/codepage.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/win32/codepage.c b/win32/codepage.c index 519ff03f4b..7206f92c05 100644 --- a/win32/codepage.c +++ b/win32/codepage.c @@ -394,7 +394,7 @@ PW32CP wchar_t *php_win32_cp_env_any_to_w(const char* env) }/*}}}*/ static BOOL php_win32_cp_cli_io_setup(void) -{ +{/*{{{*/ BOOL ret = TRUE; if (PG(input_encoding) && PG(input_encoding)[0]) { @@ -420,7 +420,7 @@ static BOOL php_win32_cp_cli_io_setup(void) } return ret; -} +}/*}}}*/ PW32CP const struct php_win32_cp *php_win32_cp_do_setup(const char *enc) {/*{{{*/ @@ -498,16 +498,18 @@ PW32CP const struct php_win32_cp *php_win32_cp_cli_do_setup(DWORD id) PW32CP const struct php_win32_cp *php_win32_cp_cli_do_restore(DWORD id) {/*{{{*/ - if (!id && orig_cp) { - id = orig_cp->id; + BOOL cli_io_restored = TRUE; + + if (orig_in_cp) { + cli_io_restored = cli_io_restored && SetConsoleCP(orig_in_cp->id); } - if (SetConsoleCP(orig_in_cp->id) && SetConsoleOutputCP(orig_out_cp->id)) { - if (orig_cp) { - return orig_cp; - } else { - return php_win32_cp_set_by_id(id); - } + if (orig_out_cp) { + cli_io_restored = cli_io_restored && SetConsoleOutputCP(orig_out_cp->id); + } + + if (cli_io_restored && id) { + return php_win32_cp_set_by_id(id); } return NULL; |