From 0a170204f411cc94c42939b53f7ef3ad05d21c24 Mon Sep 17 00:00:00 2001 From: Pierre Joye Date: Wed, 3 Jun 2009 08:07:30 +0000 Subject: [PATCH] - MFB: fix parameter order and return value check in windows (Venkat Raman Don, Pierre)' link --- ext/standard/link_win32.c | 7 +++++-- ext/standard/tests/file/link_win32.phpt | 26 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 ext/standard/tests/file/link_win32.phpt diff --git a/ext/standard/link_win32.c b/ext/standard/link_win32.c index aa4c870a24..12aa393715 100644 --- a/ext/standard/link_win32.c +++ b/ext/standard/link_win32.c @@ -230,7 +230,9 @@ PHP_FUNCTION(link) char source_p[MAXPATHLEN]; char dest_p[MAXPATHLEN]; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &topath, &topath_len, &frompath, &frompath_len) == FAILURE) { + /*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 */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &frompath, &frompath_len, &topath, &topath_len) == FAILURE) { return; } @@ -259,7 +261,8 @@ PHP_FUNCTION(link) #else ret = CreateHardLinkA(dest_p, source_p, NULL); #endif - if (ret == -1) { + + if (ret == 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno)); RETURN_FALSE; } diff --git a/ext/standard/tests/file/link_win32.phpt b/ext/standard/tests/file/link_win32.phpt new file mode 100644 index 0000000000..f2f9324f68 --- /dev/null +++ b/ext/standard/tests/file/link_win32.phpt @@ -0,0 +1,26 @@ +--TEST-- +bug # (link not working properly on Windows) +--CREDITS-- +Venkat Raman Don +--SKIPIF-- + +--FILE-- +'; +file_put_contents($filename, $content); +$linkname = __DIR__ . '\\a_link.php'; +link("$filename", "$linkname"); +var_dump(file_exists("$linkname")); +$linkcontent = file_get_contents($linkname); +var_dump($content == $linkcontent); +unlink($filename); +unlink($linkname); +?> +--EXPECT-- +bool(true) +bool(true) -- 2.50.1