Skip to content

Commit e5d9d00

Browse files
committed
add missing chunk to support mb path in symlink()
1 parent 53034fe commit e5d9d00

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

ext/standard/link_win32.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -117,22 +117,7 @@ PHP_FUNCTION(symlink)
117117
char dirname[MAXPATHLEN];
118118
size_t len;
119119
DWORD attr;
120-
HINSTANCE kernel32;
121-
typedef BOOLEAN (WINAPI *csla_func)(LPCSTR, LPCSTR, DWORD);
122-
csla_func pCreateSymbolicLinkA;
123-
124-
kernel32 = LoadLibrary("kernel32.dll");
125-
126-
if (kernel32) {
127-
pCreateSymbolicLinkA = (csla_func)GetProcAddress(kernel32, "CreateSymbolicLinkA");
128-
if (pCreateSymbolicLinkA == NULL) {
129-
php_error_docref(NULL, E_WARNING, "Can't call CreateSymbolicLinkA");
130-
RETURN_FALSE;
131-
}
132-
} else {
133-
php_error_docref(NULL, E_WARNING, "Can't call get a handle on kernel32.dll");
134-
RETURN_FALSE;
135-
}
120+
wchar_t *dstw, *srcw;
136121

137122
if (zend_parse_parameters(ZEND_NUM_ARGS(), "pp", &topath, &topath_len, &frompath, &frompath_len) == FAILURE) {
138123
return;
@@ -166,21 +151,37 @@ PHP_FUNCTION(symlink)
166151
RETURN_FALSE;
167152
}
168153

169-
if ((attr = GetFileAttributes(topath)) == INVALID_FILE_ATTRIBUTES) {
170-
php_error_docref(NULL, E_WARNING, "Could not fetch file information(error %d)", GetLastError());
171-
RETURN_FALSE;
154+
dstw = php_win32_ioutil_any_to_w(topath);
155+
if (!dstw) {
156+
php_error_docref(NULL, E_WARNING, "UTF-16 conversion failed (error %d)", GetLastError());
157+
RETURN_FALSE;
158+
}
159+
if ((attr = GetFileAttributesW(dstw)) == INVALID_FILE_ATTRIBUTES) {
160+
php_error_docref(NULL, E_WARNING, "Could not fetch file information(error %d)", GetLastError());
161+
RETURN_FALSE;
172162
}
173163

164+
srcw = php_win32_ioutil_any_to_w(source_p);
165+
if (!srcw) {
166+
free(dstw);
167+
php_error_docref(NULL, E_WARNING, "UTF-16 conversion failed (error %d)", GetLastError());
168+
RETURN_FALSE;
169+
}
174170
/* For the source, an expanded path must be used (in ZTS an other thread could have changed the CWD).
175171
* For the target the exact string given by the user must be used, relative or not, existing or not.
176172
* The target is relative to the link itself, not to the CWD. */
177-
ret = pCreateSymbolicLinkA(source_p, topath, (attr & FILE_ATTRIBUTE_DIRECTORY ? 1 : 0));
173+
ret = CreateSymbolicLinkW(srcw, dstw, (attr & FILE_ATTRIBUTE_DIRECTORY ? 1 : 0));
178174

179175
if (!ret) {
176+
free(dstw);
177+
free(srcw);
180178
php_error_docref(NULL, E_WARNING, "Cannot create symlink, error code(%d)", GetLastError());
181179
RETURN_FALSE;
182180
}
183181

182+
free(dstw);
183+
free(srcw);
184+
184185
RETURN_TRUE;
185186
}
186187
/* }}} */

0 commit comments

Comments
 (0)