summaryrefslogtreecommitdiff
path: root/sapi/cli/php_cli.c
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2016-06-20 14:59:35 +0300
committerDmitry Stogov <dmitry@zend.com>2016-06-20 14:59:35 +0300
commit6ef43be1d75e1cabb74133f0ac2e87373cc0c472 (patch)
treed389637cb75ff5a2193298d4a18912e3fbfe3963 /sapi/cli/php_cli.c
parentc8706331b5511397bee28c676d98672383222f2f (diff)
parent3d3f11ede4cc7c83d64cc5edaae7c29ce9c6986f (diff)
downloadphp-git-6ef43be1d75e1cabb74133f0ac2e87373cc0c472.tar.gz
Merge branch 'master' of git.php.net:php-src
* 'master' of git.php.net:php-src: Fixed the UTF-8 and long path support in the streams on Windows.
Diffstat (limited to 'sapi/cli/php_cli.c')
-rw-r--r--sapi/cli/php_cli.c48
1 files changed, 46 insertions, 2 deletions
diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c
index 3c7a136f4e..8a9f50eccc 100644
--- a/sapi/cli/php_cli.c
+++ b/sapi/cli/php_cli.c
@@ -39,6 +39,7 @@
#include "win32/time.h"
#include "win32/signal.h"
#include <process.h>
+#include <shellapi.h>
#endif
#if HAVE_SYS_TIME_H
#include <sys/time.h>
@@ -102,9 +103,12 @@ PHPAPI extern char *php_ini_opened_path;
PHPAPI extern char *php_ini_scanned_path;
PHPAPI extern char *php_ini_scanned_files;
-#if defined(PHP_WIN32) && defined(ZTS)
+#if defined(PHP_WIN32)
+#if defined(ZTS)
ZEND_TSRMLS_CACHE_DEFINE()
#endif
+static DWORD orig_cp = 0;
+#endif
#ifndef O_BINARY
#define O_BINARY 0
@@ -646,6 +650,17 @@ static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file,
}
/* }}} */
+/*{{{ php_cli_win32_ctrl_handler */
+#if defined(PHP_WIN32) && !defined(PHP_CLI_WIN32_NO_CONSOLE)
+BOOL WINAPI php_cli_win32_ctrl_handler(DWORD sig)
+{
+ (void)php_win32_cp_cli_do_restore(orig_cp);
+
+ return FALSE;
+}
+#endif
+/*}}}*/
+
static int do_cli(int argc, char **argv) /* {{{ */
{
int c;
@@ -1171,9 +1186,16 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
int main(int argc, char *argv[])
#endif
{
-#ifdef PHP_CLI_WIN32_NO_CONSOLE
+#if defined(PHP_WIN32)
+# ifdef PHP_CLI_WIN32_NO_CONSOLE
int argc = __argc;
char **argv = __argv;
+# else
+ int num_args;
+ wchar_t **argv_wide;
+ char **argv_save = argv;
+ BOOL using_wide_argv = 0;
+# endif
#endif
int c;
@@ -1338,6 +1360,19 @@ exit_loop:
}
module_started = 1;
+#if defined(PHP_WIN32) && !defined(PHP_CLI_WIN32_NO_CONSOLE)
+ php_win32_cp_cli_setup();
+ orig_cp = (php_win32_cp_get_orig())->id;
+ /* Ignore the delivered argv and argc, read from W API. This place
+ might be too late though, but this is the earliest place ATW
+ we can access the internal charset information from PHP. */
+ argv_wide = CommandLineToArgvW(GetCommandLineW(), &num_args);
+ PHP_WIN32_CP_W_TO_A_ARRAY(argv_wide, num_args, argv, argc)
+ using_wide_argv = 1;
+
+ SetConsoleCtrlHandler(php_cli_win32_ctrl_handler, TRUE);
+#endif
+
/* -e option */
if (use_extended_info) {
CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO;
@@ -1371,6 +1406,15 @@ out:
tsrm_shutdown();
#endif
+#if defined(PHP_WIN32) && !defined(PHP_CLI_WIN32_NO_CONSOLE)
+ (void)php_win32_cp_cli_restore();
+
+ if (using_wide_argv) {
+ PHP_WIN32_FREE_ARRAY(argv, argc);
+ LocalFree(argv_wide);
+ }
+ argv = argv_save;
+#endif
/*
* Do not move this de-initialization. It needs to happen right before
* exiting.