int ret;
char source_p[MAXPATHLEN];
char dest_p[MAXPATHLEN];
+ wchar_t *dstw, *srcw;
/*First argument to link function is the target and hence should go to frompath
Second argument to link function is the link itself and hence should go to topath */
}
#ifndef ZTS
- ret = CreateHardLinkA(topath, frompath, NULL);
+# define _TO_PATH topath
+# define _FROM_PATH frompath
#else
- ret = CreateHardLinkA(dest_p, source_p, NULL);
+# define _TO_PATH dest_p
+# define _FROM_PATH source_p
#endif
+ dstw = php_win32_ioutil_any_to_w(_TO_PATH);
+ if (!dstw) {
+ php_error_docref(NULL, E_WARNING, "UTF-16 conversion failed (error %d)", GetLastError());
+ RETURN_FALSE;
+ }
+ srcw = php_win32_ioutil_any_to_w(_FROM_PATH);
+ if (!srcw) {
+ free(dstw);
+ php_error_docref(NULL, E_WARNING, "UTF-16 conversion failed (error %d)", GetLastError());
+ RETURN_FALSE;
+ }
+#undef _TO_PATH
+#undef _FROM_PATH
+
+ ret = CreateHardLinkW(dstw, srcw, NULL);
if (ret == 0) {
+ free(dstw);
+ free(srcw);
php_error_docref(NULL, E_WARNING, "%s", strerror(errno));
RETURN_FALSE;
}
+ free(dstw);
+ free(srcw);
+
RETURN_TRUE;
}
/* }}} */
--- /dev/null
+--TEST--
+Bug #76335 "link(): Bad file descriptor" with non-ASCII path
+--SKIPIF--
+<?php
+if(substr(PHP_OS, 0, 3) != 'WIN' ) {
+ die('skip windows only test');
+}
+?>
+--FILE--
+<?php
+
+$d0 = dirname(__FILE__) . DIRECTORY_SEPARATOR . "á";
+$d1 = dirname(__FILE__) . DIRECTORY_SEPARATOR . "a";
+
+$fn = dirname(__FILE__) . DIRECTORY_SEPARATOR . "file";
+
+$l0 = $d0 . DIRECTORY_SEPARATOR . "b";
+$l1 = $d1 . DIRECTORY_SEPARATOR . "b";
+
+mkdir($d0);
+mkdir($d1);
+
+file_put_contents($fn, "");
+
+chdir($d0);
+var_dump(link($d0 . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "file", $l0));
+
+chdir($d1);
+var_dump(link($d1 . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "file", $l1));
+
+?>
+--CLEAN--
+<?php
+
+$d0 = dirname(__FILE__) . DIRECTORY_SEPARATOR . "á";
+$d1 = dirname(__FILE__) . DIRECTORY_SEPARATOR . "a";
+
+$fn = dirname(__FILE__) . DIRECTORY_SEPARATOR . "file";
+
+$l0 = $d0 . DIRECTORY_SEPARATOR . "b";
+$l1 = $d1 . DIRECTORY_SEPARATOR . "b";
+
+unlink($l0);
+unlink($l1);
+unlink($fn);
+rmdir($d0);
+rmdir($d1);
+?>
+--EXPECT--
+bool(true)
+bool(true)
+