]> granicus.if.org Git - php/commitdiff
add missing chunk to support mb path in symlink()
authorAnatol Belski <ab@php.net>
Thu, 11 Aug 2016 11:35:12 +0000 (13:35 +0200)
committerAnatol Belski <ab@php.net>
Thu, 11 Aug 2016 11:38:28 +0000 (13:38 +0200)
ext/standard/link_win32.c

index 56ab4500c404c9b031e6bc5d70060c846f1518b6..1bc5aa9d3df62dc23440c1aa672601539e54052f 100644 (file)
@@ -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;
 }
 /* }}} */