com php-src: Rework mkdir impl and expose wide char variant: win32/ioutil.c win32/ioutil.h
| From: | Anatol Belski | Date: | Fri, 08 Dec 2017 23:11:33 +0000 |
| Subject: | com php-src: Rework mkdir impl and expose wide char variant: win32/ioutil.c win32/ioutil.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-100532@lists.php.net to get a copy of this message | ||
Commit: 94f16f1961a856d6db70faf9223e110aaff73c7a
Author: Anatol Belski <ab@php.net> Sat, 9 Dec 2017 00:11:33 +0100
Parents: 6bd18c0f0b40e1213b906fb78a191e341678e172
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=94f16f1961a856d6db70faf9223e110aaff73c7a
Log:
Rework mkdir impl and expose wide char variant
Changed paths:
M win32/ioutil.c
M win32/ioutil.h
Diff:
diff --git a/win32/ioutil.c b/win32/ioutil.c
index 72b87b1..562767b 100644
--- a/win32/ioutil.c
+++ b/win32/ioutil.c
@@ -282,33 +282,20 @@ PW32IO int php_win32_ioutil_close(int fd)
return result;
}/*}}}*/
-#if 0
PW32IO int php_win32_ioutil_mkdir_w(const wchar_t *path, mode_t mode)
{/*{{{*/
- int ret = 0;
- DWORD err = 0;
-
- PHP_WIN32_IOUTIL_CHECK_PATH_W(path, -1, 0)
+ size_t path_len;
+ wchar_t *my_path;
- /* TODO extend with mode usage */
- if (!CreateDirectoryW(path, NULL)) {
- err = GetLastError();
- ret = -1;
- SET_ERRNO_FROM_WIN32_CODE(err);
+ if (!path) {
+ SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER);
+ return -1;
}
- return ret;
-}/*}}}*/
-#endif
-
-PW32IO int php_win32_ioutil_mkdir(const char *path, mode_t mode)
-{/*{{{*/
- size_t pathw_len = 0;
- wchar_t *pathw = php_win32_ioutil_conv_any_to_w(path, 0, &pathw_len);
- int ret = 0;
- DWORD err = 0;
+ PHP_WIN32_IOUTIL_CHECK_PATH_W(path, -1, 0)
- if (pathw_len < _MAX_PATH && pathw_len > _MAX_PATH - 12) {
+ path_len = wcslen(path);
+ if (path_len < _MAX_PATH && path_len > _MAX_PATH - 12) {
/* Special case here. From the doc:
"When using an API to create a directory, the specified path cannot be
@@ -318,41 +305,36 @@ PW32IO int php_win32_ioutil_mkdir(const char *path, mode_t mode)
already needs to be a long path. The given path is already normalized
and prepared, need only to prefix it.
*/
- wchar_t *tmp = (wchar_t *) malloc((pathw_len + PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW + 1) *
sizeof(wchar_t));
+ wchar_t *tmp = (wchar_t *) malloc((path_len + PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW + 1) *
sizeof(wchar_t));
if (!tmp) {
- free(pathw);
SET_ERRNO_FROM_WIN32_CODE(ERROR_NOT_ENOUGH_MEMORY);
return -1;
}
memmove(tmp, PHP_WIN32_IOUTIL_LONG_PATH_PREFIXW, PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW *
sizeof(wchar_t));
- memmove(tmp+PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW, pathw, pathw_len * sizeof(wchar_t));
- pathw_len += PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW;
- tmp[pathw_len] = L'\0';
+ memmove(tmp+PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW, path, path_len * sizeof(wchar_t));
+ path_len += PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW;
+ tmp[path_len] = L'\0';
- free(pathw);
- pathw = tmp;
+ my_path = tmp;
+ } else {
+ my_path = path;
}
- /* TODO extend with mode usage */
- if (!pathw) {
- SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER);
+ if (!CreateDirectoryW(my_path, NULL)) {
+ DWORD err = GetLastError();
+ if (my_path != path) {
+ free((void *)my_path);
+ }
+ SET_ERRNO_FROM_WIN32_CODE(err);
return -1;
}
- PHP_WIN32_IOUTIL_CHECK_PATH_W(pathw, -1, 1)
-
- if (!CreateDirectoryW(pathw, NULL)) {
- err = GetLastError();
- ret = -1;
+ if (my_path != path) {
+ free((void *)my_path);
}
- free(pathw);
- if (0 > ret) {
- SET_ERRNO_FROM_WIN32_CODE(err);
- }
-
- return ret;
+ return 0;
}/*}}}*/
PW32IO int php_win32_ioutil_unlink_w(const wchar_t *path)
diff --git a/win32/ioutil.h b/win32/ioutil.h
index e886e6f..311e448 100644
--- a/win32/ioutil.h
+++ b/win32/ioutil.h
@@ -248,7 +248,6 @@ __forceinline static wchar_t *php_win32_ioutil_conv_any_to_w(const char* in, siz
PW32IO int php_win32_ioutil_close(int fd);
PW32IO BOOL php_win32_ioutil_posix_to_open_opts(int flags, mode_t mode, php_ioutil_open_opts
*opts);
-PW32IO int php_win32_ioutil_mkdir(const char *path, mode_t mode);
PW32IO size_t php_win32_ioutil_dirname(char *buf, size_t len);
PW32IO int php_win32_ioutil_open_w(const wchar_t *path, int flags, ...);
@@ -257,6 +256,7 @@ PW32IO int php_win32_ioutil_rename_w(const wchar_t *oldname, const wchar_t *newn
PW32IO wchar_t *php_win32_ioutil_getcwd_w(wchar_t *buf, size_t len);
PW32IO int php_win32_ioutil_unlink_w(const wchar_t *path);
PW32IO int php_win32_ioutil_access_w(const wchar_t *path, mode_t mode);
+PW32IO int php_win32_ioutil_mkdir_w(const wchar_t *path, mode_t mode);
#if 0
PW32IO int php_win32_ioutil_mkdir_w(const wchar_t *path, mode_t mode);
@@ -554,6 +554,31 @@ __forceinline static int php_win32_ioutil_chmod(const char *patha, int mode)
return ret;
}/*}}}*/
+__forceinline static int php_win32_ioutil_mkdir(const char *path, mode_t mode)
+{/*{{{*/
+ int ret;
+ wchar_t *pathw = php_win32_ioutil_any_to_w(path);
+ DWORD err = 0;
+
+ if (!pathw) {
+ SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER);
+ return -1;
+ }
+
+ ret = php_win32_ioutil_mkdir_w(pathw, mode);
+ if (0 > ret) {
+ err = GetLastError();
+ }
+
+ free(pathw);
+
+ if (0 > ret) {
+ SET_ERRNO_FROM_WIN32_CODE(err);
+ }
+
+ return ret;
+}/*}}}*/
+
#ifdef __cplusplus
}
#endif