com php-src: add missing chunk to support mb path in symlink(): ext/standard/link_win32.c
| From: | Anatol Belski | Date: | Thu, 11 Aug 2016 11:38:28 +0000 |
| Subject: | com php-src: add missing chunk to support mb path in symlink(): ext/standard/link_win32.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-93745@lists.php.net to get a copy of this message | ||
Commit: e5d9d009cf80685b78ca920692bf5d536998239c
Author: Anatol Belski <ab@php.net> Thu, 11 Aug 2016 13:35:12 +0200
Parents: 53034feda530278579058542d0bb335aad154951
Branches: PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=e5d9d009cf80685b78ca920692bf5d536998239c
Log:
add missing chunk to support mb path in symlink()
Changed paths:
M ext/standard/link_win32.c
Diff:
diff --git a/ext/standard/link_win32.c b/ext/standard/link_win32.c
index 56ab450..1bc5aa9 100644
--- a/ext/standard/link_win32.c
+++ b/ext/standard/link_win32.c
@@ -117,22 +117,7 @@ PHP_FUNCTION(symlink)
char dirname[MAXPATHLEN];
size_t len;
DWORD attr;
- HINSTANCE kernel32;
- typedef BOOLEAN (WINAPI *csla_func)(LPCSTR, LPCSTR, DWORD);
- csla_func pCreateSymbolicLinkA;
-
- kernel32 = LoadLibrary("kernel32.dll");
-
- if (kernel32) {
- pCreateSymbolicLinkA = (csla_func)GetProcAddress(kernel32, "CreateSymbolicLinkA");
- if (pCreateSymbolicLinkA == NULL) {
- php_error_docref(NULL, E_WARNING, "Can't call CreateSymbolicLinkA");
- RETURN_FALSE;
- }
- } else {
- php_error_docref(NULL, E_WARNING, "Can't call get a handle on kernel32.dll");
- RETURN_FALSE;
- }
+ wchar_t *dstw, *srcw;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "pp", &topath, &topath_len,
&frompath, &frompath_len) == FAILURE) {
return;
@@ -166,21 +151,37 @@ PHP_FUNCTION(symlink)
RETURN_FALSE;
}
- if ((attr = GetFileAttributes(topath)) == INVALID_FILE_ATTRIBUTES) {
- php_error_docref(NULL, E_WARNING, "Could not fetch file information(error %d)",
GetLastError());
- RETURN_FALSE;
+ dstw = php_win32_ioutil_any_to_w(topath);
+ if (!dstw) {
+ php_error_docref(NULL, E_WARNING, "UTF-16 conversion failed (error %d)",
GetLastError());
+ RETURN_FALSE;
+ }
+ if ((attr = GetFileAttributesW(dstw)) == INVALID_FILE_ATTRIBUTES) {
+ php_error_docref(NULL, E_WARNING, "Could not fetch file information(error %d)",
GetLastError());
+ RETURN_FALSE;
}
+ srcw = php_win32_ioutil_any_to_w(source_p);
+ if (!srcw) {
+ free(dstw);
+ php_error_docref(NULL, E_WARNING, "UTF-16 conversion failed (error %d)",
GetLastError());
+ RETURN_FALSE;
+ }
/* For the source, an expanded path must be used (in ZTS an other thread could have changed the
CWD).
* For the target the exact string given by the user must be used, relative or not, existing or
not.
* The target is relative to the link itself, not to the CWD. */
- ret = pCreateSymbolicLinkA(source_p, topath, (attr & FILE_ATTRIBUTE_DIRECTORY ? 1 : 0));
+ ret = CreateSymbolicLinkW(srcw, dstw, (attr & FILE_ATTRIBUTE_DIRECTORY ? 1 : 0));
if (!ret) {
+ free(dstw);
+ free(srcw);
php_error_docref(NULL, E_WARNING, "Cannot create symlink, error code(%d)",
GetLastError());
RETURN_FALSE;
}
+ free(dstw);
+ free(srcw);
+
RETURN_TRUE;
}
/* }}} */