summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/main.c27
-rw-r--r--main/php.h5
-rw-r--r--main/php_open_temporary_file.c55
-rw-r--r--main/streams/plain_wrapper.c12
4 files changed, 85 insertions, 14 deletions
diff --git a/main/main.c b/main/main.c
index ad65483437..195e46f5bb 100644
--- a/main/main.c
+++ b/main/main.c
@@ -386,10 +386,27 @@ static PHP_INI_DISP(display_errors_mode)
/* {{{ PHP_INI_MH
*/
+static PHP_INI_MH(OnUpdateDefaultCharset)
+{
+ if (new_value) {
+ OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
+#ifdef PHP_WIN32
+ php_win32_cp_do_update(ZSTR_VAL(new_value));
+#endif
+ }
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ PHP_INI_MH
+ */
static PHP_INI_MH(OnUpdateInternalEncoding)
{
if (new_value) {
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
+#ifdef PHP_WIN32
+ php_win32_cp_do_update(ZSTR_VAL(new_value));
+#endif
}
return SUCCESS;
}
@@ -523,7 +540,7 @@ PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("auto_append_file", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, auto_append_file, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("auto_prepend_file", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, auto_prepend_file, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("doc_root", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, doc_root, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("default_charset", PHP_DEFAULT_CHARSET, PHP_INI_ALL, OnUpdateString, default_charset, sapi_globals_struct, sapi_globals)
+ STD_PHP_INI_ENTRY("default_charset", PHP_DEFAULT_CHARSET, PHP_INI_ALL, OnUpdateDefaultCharset, default_charset, sapi_globals_struct, sapi_globals)
STD_PHP_INI_ENTRY("default_mimetype", SAPI_DEFAULT_MIMETYPE, PHP_INI_ALL, OnUpdateString, default_mimetype, sapi_globals_struct, sapi_globals)
STD_PHP_INI_ENTRY("internal_encoding", NULL, PHP_INI_ALL, OnUpdateInternalEncoding, internal_encoding, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("input_encoding", NULL, PHP_INI_ALL, OnUpdateInputEncoding, input_encoding, php_core_globals, core_globals)
@@ -1240,15 +1257,17 @@ PHPAPI char *php_get_current_user(void)
return "";
} else {
#ifdef PHP_WIN32
- char name[256];
- DWORD len = sizeof(name)-1;
+ char *name = php_win32_get_username();
+ int len;
- if (!GetUserName(name, &len)) {
+ if (!name) {
return "";
}
+ len = (int)strlen(name);
name[len] = '\0';
SG(request_info).current_user_length = len;
SG(request_info).current_user = estrndup(name, len);
+ free(name);
return SG(request_info).current_user;
#else
struct passwd *pwd;
diff --git a/main/php.h b/main/php.h
index ed6a4d7189..8eb1c53e8b 100644
--- a/main/php.h
+++ b/main/php.h
@@ -248,7 +248,10 @@ END_EXTERN_C()
#define STR_PRINT(str) ((str)?(str):"")
#ifndef MAXPATHLEN
-# ifdef PATH_MAX
+# if PHP_WIN32
+# include "win32/ioutil.h"
+# define MAXPATHLEN PHP_WIN32_IOUTIL_MAXPATHLEN
+# elif PATH_MAX
# define MAXPATHLEN PATH_MAX
# elif defined(MAX_PATH)
# define MAXPATHLEN MAX_PATH
diff --git a/main/php_open_temporary_file.c b/main/php_open_temporary_file.c
index caddf1b390..7b0f88762d 100644
--- a/main/php_open_temporary_file.c
+++ b/main/php_open_temporary_file.c
@@ -98,7 +98,13 @@
static int php_do_open_temporary_file(const char *path, const char *pfx, zend_string **opened_path_p)
{
char *trailing_slash;
+#ifdef PHP_WIN32
+ char *opened_path = NULL;
+ size_t opened_path_len;
+ wchar_t *cwdw, *pfxw, pathw[MAXPATHLEN];
+#else
char opened_path[MAXPATHLEN];
+#endif
char cwd[MAXPATHLEN];
cwd_state new_state;
int fd = -1;
@@ -139,23 +145,47 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, zend_st
trailing_slash = "/";
}
+#ifndef PHP_WIN32
if (snprintf(opened_path, MAXPATHLEN, "%s%s%sXXXXXX", new_state.cwd, trailing_slash, pfx) >= MAXPATHLEN) {
efree(new_state.cwd);
return -1;
}
+#endif
#ifdef PHP_WIN32
+ cwdw = php_win32_ioutil_any_to_w(new_state.cwd);
+ pfxw = php_win32_ioutil_any_to_w(pfx);
+ if (!cwdw || !pfxw) {
+ free(cwdw);
+ free(pfxw);
+ efree(new_state.cwd);
+ return -1;
+ }
+
+ if (GetTempFileNameW(cwdw, pfxw, 0, pathw)) {
+ opened_path = php_win32_ioutil_conv_w_to_any(pathw, PHP_WIN32_CP_IGNORE_LEN, &opened_path_len);
+ if (!opened_path || opened_path_len >= MAXPATHLEN) {
+ free(cwdw);
+ free(pfxw);
+ efree(new_state.cwd);
+ return -1;
+ }
+ assert(strlen(opened_path) == opened_path_len);
- if (GetTempFileName(new_state.cwd, pfx, 0, opened_path)) {
/* Some versions of windows set the temp file to be read-only,
* which means that opening it will fail... */
if (VCWD_CHMOD(opened_path, 0600)) {
+ free(cwdw);
+ free(pfxw);
efree(new_state.cwd);
+ free(opened_path);
return -1;
}
fd = VCWD_OPEN_MODE(opened_path, open_flags, 0600);
}
+ free(cwdw);
+ free(pfxw);
#elif defined(HAVE_MKSTEMP)
fd = mkstemp(opened_path);
#else
@@ -164,9 +194,16 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, zend_st
}
#endif
+#ifdef PHP_WIN32
+ if (fd != -1 && opened_path_p) {
+ *opened_path_p = zend_string_init(opened_path, opened_path_len, 0);
+ }
+ free(opened_path);
+#else
if (fd != -1 && opened_path_p) {
*opened_path_p = zend_string_init(opened_path, strlen(opened_path), 0);
}
+#endif
efree(new_state.cwd);
return fd;
}
@@ -204,14 +241,18 @@ PHPAPI const char* php_get_temporary_directory(void)
* the environment values TMP and TEMP (in order) first.
*/
{
- char sTemp[MAX_PATH];
- DWORD len = GetTempPath(sizeof(sTemp),sTemp);
+ wchar_t sTemp[MAXPATHLEN];
+ char *tmp;
+ size_t len = GetTempPathW(MAXPATHLEN, sTemp);
assert(0 < len); /* should *never* fail! */
- if (sTemp[len - 1] == DEFAULT_SLASH) {
- PG(php_sys_temp_dir) = estrndup(sTemp, len - 1);
- } else {
- PG(php_sys_temp_dir) = estrndup(sTemp, len);
+
+ if (NULL == (tmp = php_win32_ioutil_conv_w_to_any(sTemp, len, &len))) {
+ return NULL;
}
+
+ PG(php_sys_temp_dir) = estrndup(tmp, len - 1);
+
+ free(tmp);
return PG(php_sys_temp_dir);
}
#else
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c
index d510c909a7..7ede3718b5 100644
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@ -42,6 +42,8 @@
#ifdef PHP_WIN32
# include "win32/winutil.h"
# include "win32/time.h"
+# include "win32/ioutil.h"
+# include "win32/readdir.h"
#endif
#define php_stream_fopen_from_fd_int(fd, mode, persistent_id) _php_stream_fopen_from_fd_int((fd), (mode), (persistent_id) STREAMS_CC)
@@ -465,7 +467,11 @@ static int php_stdiop_close(php_stream *stream, int close_handle)
return 0; /* everything should be closed already -> success */
}
if (data->temp_name) {
+#ifdef PHP_WIN32
+ php_win32_ioutil_unlink(ZSTR_VAL(data->temp_name));
+#else
unlink(ZSTR_VAL(data->temp_name));
+#endif
/* temporary streams are never persistent */
zend_string_release(data->temp_name);
data->temp_name = NULL;
@@ -987,9 +993,11 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, zen
return ret;
}
}
-
+#ifdef PHP_WIN32
+ fd = php_win32_ioutil_open(realpath, open_flags, 0666);
+#else
fd = open(realpath, open_flags, 0666);
-
+#endif
if (fd != -1) {
if (options & STREAM_OPEN_FOR_INCLUDE) {