pajoye Fri, 10 Sep 2010 14:01:44 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=303256
Log:
- add php_sys_readlink
Changed paths:
U php/php-src/branches/PHP_5_3/TSRM/tsrm_virtual_cwd.c
U php/php-src/branches/PHP_5_3/TSRM/tsrm_virtual_cwd.h
U php/php-src/branches/PHP_5_3/UPGRADING.INTERNALS
U php/php-src/trunk/TSRM/tsrm_virtual_cwd.c
U php/php-src/trunk/TSRM/tsrm_virtual_cwd.h
U php/php-src/trunk/UPGRADING.INTERNALS
Modified: php/php-src/branches/PHP_5_3/TSRM/tsrm_virtual_cwd.c
===================================================================
--- php/php-src/branches/PHP_5_3/TSRM/tsrm_virtual_cwd.c 2010-09-10
13:22:05 UTC (rev 303255)
+++ php/php-src/branches/PHP_5_3/TSRM/tsrm_virtual_cwd.c 2010-09-10
14:01:44 UTC (rev 303256)
@@ -207,6 +207,60 @@
return (time_t)UnixTime;
}
+CWD_API int php_sys_readlink(const char *link, char *target, size_t
target_len){ /* {{{ */
+ HINSTANCE kernel32;
+ HANDLE hFile;
+ DWORD dwRet;
+
+ typedef BOOL (WINAPI *gfpnh_func)(HANDLE, LPTSTR, DWORD, DWORD);
+ gfpnh_func pGetFinalPathNameByHandle;
+
+ kernel32 = LoadLibrary("kernel32.dll");
+
+ if (kernel32) {
+ pGetFinalPathNameByHandle =
(gfpnh_func)GetProcAddress(kernel32, "GetFinalPathNameByHandleA");
+ if (pGetFinalPathNameByHandle == NULL) {
+ return -1;
+ }
+ } else {
+ return -1;
+ }
+
+ hFile = CreateFile(link, // file to open
+ GENERIC_READ, // open for reading
+ FILE_SHARE_READ, // share for reading
+ NULL, // default security
+ OPEN_EXISTING, // existing file only
+ FILE_FLAG_BACKUP_SEMANTICS, // normal file
+ NULL); // no attr. template
+
+ if( hFile == INVALID_HANDLE_VALUE) {
+ return -1;
+ }
+
+ dwRet = pGetFinalPathNameByHandle(hFile, target, MAXPATHLEN,
VOLUME_NAME_DOS);
+ if(dwRet >= MAXPATHLEN) {
+ return -1;
+ }
+
+ CloseHandle(hFile);
+
+ if(dwRet > 4) {
+ /* Skip first 4 characters if they are "\??\" */
+ if(target[0] == '\\' && target[1] == '\\' && target[2] == '?'
&& target[3] == '\\') {
+ char tmp[MAXPATHLEN];
+
+ dwRet -= 4;
+ memcpy(tmp, target + 4, dwRet);
+ memcpy(target, tmp, dwRet);
+ }
+ }
+
+ target[dwRet] = '\0';
+ return dwRet;
+}
+/* }}} */
+
CWD_API int php_sys_stat_ex(const char *path, struct stat *buf, int lstat) /*
{{{ */
{
WIN32_FILE_ATTRIBUTE_DATA data;
@@ -756,7 +810,7 @@
tmp = tsrm_do_alloca(len+1, use_heap);
memcpy(tmp, path, len+1);
- if(save &&
+ if(save &&
!(IS_UNC_PATH(path, len) && len >= 3 && path[2]
!= '?') &&
(data.dwFileAttributes &
FILE_ATTRIBUTE_REPARSE_POINT)) {
/* File is a reparse point. Get the target */
Modified: php/php-src/branches/PHP_5_3/TSRM/tsrm_virtual_cwd.h
===================================================================
--- php/php-src/branches/PHP_5_3/TSRM/tsrm_virtual_cwd.h 2010-09-10
13:22:05 UTC (rev 303255)
+++ php/php-src/branches/PHP_5_3/TSRM/tsrm_virtual_cwd.h 2010-09-10
14:01:44 UTC (rev 303256)
@@ -133,9 +133,13 @@
CWD_API int php_sys_stat_ex(const char *path, struct stat *buf, int lstat);
# define php_sys_stat(path, buf) php_sys_stat_ex(path, buf, 0)
# define php_sys_lstat(path, buf) php_sys_stat_ex(path, buf, 1)
+CWD_API int php_sys_readlink(link, target, target_len);
#else
# define php_sys_stat stat
# define php_sys_lstat lstat
+# ifdef HAVE_SYMLINK
+# define php_sys_readlink(link, target, target_len) readlink(link, target,
target_len)
+# endif
#endif
typedef struct _cwd_state {
Modified: php/php-src/branches/PHP_5_3/UPGRADING.INTERNALS
===================================================================
--- php/php-src/branches/PHP_5_3/UPGRADING.INTERNALS 2010-09-10 13:22:05 UTC
(rev 303255)
+++ php/php-src/branches/PHP_5_3/UPGRADING.INTERNALS 2010-09-10 14:01:44 UTC
(rev 303256)
@@ -8,9 +8,16 @@
1. Internal API changes
========================
- b. stat/lstat support
+ a. stat/lstat support
lstat is now available on all platforms. On unix-like platform
php_sys_lstat is an alias to lstat (when avaible). On Windows it is now
available using php_sys_lstat. php_sys_stat and php_sys_lstat usage is
recommended
instead of calling lstat directly, to ensure portability.
+
+ b. readlink support
+
+readlink is now available on all platforms. On unix-like platform
+php_sys_readlink is an alias to readlink (when avaible). On Windows it is now
+available using php_sys_readlink. php_sys_readlink usage is recommended
+instead of calling readlink directly, to ensure portability.
Modified: php/php-src/trunk/TSRM/tsrm_virtual_cwd.c
===================================================================
--- php/php-src/trunk/TSRM/tsrm_virtual_cwd.c 2010-09-10 13:22:05 UTC (rev
303255)
+++ php/php-src/trunk/TSRM/tsrm_virtual_cwd.c 2010-09-10 14:01:44 UTC (rev
303256)
@@ -207,6 +207,60 @@
return (time_t)UnixTime;
}
+CWD_API int php_sys_readlink(const char *link, char *target, size_t
target_len){ /* {{{ */
+ HINSTANCE kernel32;
+ HANDLE hFile;
+ DWORD dwRet;
+
+ typedef BOOL (WINAPI *gfpnh_func)(HANDLE, LPTSTR, DWORD, DWORD);
+ gfpnh_func pGetFinalPathNameByHandle;
+
+ kernel32 = LoadLibrary("kernel32.dll");
+
+ if (kernel32) {
+ pGetFinalPathNameByHandle =
(gfpnh_func)GetProcAddress(kernel32, "GetFinalPathNameByHandleA");
+ if (pGetFinalPathNameByHandle == NULL) {
+ return -1;
+ }
+ } else {
+ return -1;
+ }
+
+ hFile = CreateFile(link, // file to open
+ GENERIC_READ, // open for reading
+ FILE_SHARE_READ, // share for reading
+ NULL, // default security
+ OPEN_EXISTING, // existing file only
+ FILE_FLAG_BACKUP_SEMANTICS, // normal file
+ NULL); // no attr. template
+
+ if( hFile == INVALID_HANDLE_VALUE) {
+ return -1;
+ }
+
+ dwRet = pGetFinalPathNameByHandle(hFile, target, MAXPATHLEN,
VOLUME_NAME_DOS);
+ if(dwRet >= MAXPATHLEN) {
+ return -1;
+ }
+
+ CloseHandle(hFile);
+
+ if(dwRet > 4) {
+ /* Skip first 4 characters if they are "\??\" */
+ if(target[0] == '\\' && target[1] == '\\' && target[2] == '?'
&& target[3] == '\\') {
+ char tmp[MAXPATHLEN];
+
+ dwRet -= 4;
+ memcpy(tmp, target + 4, dwRet);
+ memcpy(target, tmp, dwRet);
+ }
+ }
+
+ target[dwRet] = '\0';
+ return dwRet;
+}
+/* }}} */
+
CWD_API int php_sys_stat_ex(const char *path, struct stat *buf, int lstat) /*
{{{ */
{
WIN32_FILE_ATTRIBUTE_DATA data;
Modified: php/php-src/trunk/TSRM/tsrm_virtual_cwd.h
===================================================================
--- php/php-src/trunk/TSRM/tsrm_virtual_cwd.h 2010-09-10 13:22:05 UTC (rev
303255)
+++ php/php-src/trunk/TSRM/tsrm_virtual_cwd.h 2010-09-10 14:01:44 UTC (rev
303256)
@@ -133,9 +133,13 @@
CWD_API int php_sys_stat_ex(const char *path, struct stat *buf, int lstat);
# define php_sys_stat(path, buf) php_sys_stat_ex(path, buf, 0)
# define php_sys_lstat(path, buf) php_sys_stat_ex(path, buf, 1)
+CWD_API int php_sys_readlink(link, target, target_len);
#else
# define php_sys_stat stat
# define php_sys_lstat lstat
+# ifdef HAVE_SYMLINK
+# define php_sys_readlink(link, target, target_len) readlink(link, target,
target_len)
+# endif
#endif
typedef struct _cwd_state {
Modified: php/php-src/trunk/UPGRADING.INTERNALS
===================================================================
--- php/php-src/trunk/UPGRADING.INTERNALS 2010-09-10 13:22:05 UTC (rev
303255)
+++ php/php-src/trunk/UPGRADING.INTERNALS 2010-09-10 14:01:44 UTC (rev
303256)
@@ -20,3 +20,10 @@
php_sys_lstat is an alias to lstat (when avaible). On Windows it is now
available using php_sys_lstat. php_sys_stat and php_sys_lstat usage is
recommended
instead of calling lstat directly, to ensure portability.
+
+ b. readlink support
+
+readlink is now available on all platforms. On unix-like platform
+php_sys_readlink is an alias to readlink (when avaible). On Windows it is now
+available using php_sys_readlink. php_sys_readlink usage is recommended
+instead of calling readlink directly, to ensure portability.
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php