@@ -117,22 +117,7 @@ PHP_FUNCTION(symlink)
117
117
char dirname [MAXPATHLEN ];
118
118
size_t len ;
119
119
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 ;
136
121
137
122
if (zend_parse_parameters (ZEND_NUM_ARGS (), "pp" , & topath , & topath_len , & frompath , & frompath_len ) == FAILURE ) {
138
123
return ;
@@ -166,21 +151,37 @@ PHP_FUNCTION(symlink)
166
151
RETURN_FALSE ;
167
152
}
168
153
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 ;
172
162
}
173
163
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
+ }
174
170
/* For the source, an expanded path must be used (in ZTS an other thread could have changed the CWD).
175
171
* For the target the exact string given by the user must be used, relative or not, existing or not.
176
172
* 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 ));
178
174
179
175
if (!ret ) {
176
+ free (dstw );
177
+ free (srcw );
180
178
php_error_docref (NULL , E_WARNING , "Cannot create symlink, error code(%d)" , GetLastError ());
181
179
RETURN_FALSE ;
182
180
}
183
181
182
+ free (dstw );
183
+ free (srcw );
184
+
184
185
RETURN_TRUE ;
185
186
}
186
187
/* }}} */
0 commit comments