From ecb5c7e08edea0a1cc17d4c6477f77819e3b6842 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Mon, 4 Nov 2002 23:24:15 +0000 Subject: [PATCH] Revert virtual_link() patch. --- TSRM/tsrm_virtual_cwd.c | 41 ++++++++++++----------------------------- TSRM/tsrm_virtual_cwd.h | 3 +-- ext/standard/link.c | 8 +++----- 3 files changed, 16 insertions(+), 36 deletions(-) diff --git a/TSRM/tsrm_virtual_cwd.c b/TSRM/tsrm_virtual_cwd.c index 01e1fe9eda5..748fb608e49 100644 --- a/TSRM/tsrm_virtual_cwd.c +++ b/TSRM/tsrm_virtual_cwd.c @@ -282,29 +282,6 @@ CWD_API char *virtual_getcwd(char *buf, size_t size TSRMLS_DC) return buf; } -CWD_API char *virtual_link(char *buf, size_t size TSRMLS_DC) -{ - char *p; - char tmp_path[MAXPATHLEN * 2]; - char resolved_path[MAXPATHLEN]; - - if (IS_ABSOLUTE_PATH(buf, size)) { - p = resolved_path; - memcpy(p, buf, size); - p[size] = '\0'; - } else { - virtual_getcwd(tmp_path, MAXPATHLEN TSRMLS_CC); - p = tmp_path + strlen(tmp_path); - *p++ = '/'; - memcpy(p, buf, size); - *(p + size) = '\0'; - - p = tmp_path; - } - - return p; -} - /* Resolve path relatively to state and put the real path into state */ /* returns 0 for ok, 1 for error */ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path) @@ -709,24 +686,30 @@ CWD_API int virtual_stat(const char *path, struct stat_libc *buf TSRMLS_DC) #if !defined(TSRM_WIN32) && !defined(NETWARE) CWD_API int virtual_lstat(const char *path, struct stat *buf TSRMLS_DC) { + cwd_state new_state; int retval; - char *p; - p = virtual_link((char *)path, strlen(path) TSRMLS_CC); - retval = lstat(p, buf); + CWD_STATE_COPY(&new_state, &CWDG(cwd)); + virtual_file_ex(&new_state, path, NULL); + + retval = lstat(new_state.cwd, buf); + CWD_STATE_FREE(&new_state); return retval; } #endif CWD_API int virtual_unlink(const char *path TSRMLS_DC) { + cwd_state new_state; int retval; - char *resolved_path; - resolved_path = virtual_link((char *)path, strlen(path) TSRMLS_CC); - retval = unlink(resolved_path); + CWD_STATE_COPY(&new_state, &CWDG(cwd)); + virtual_file_ex(&new_state, path, NULL); + retval = unlink(new_state.cwd); + + CWD_STATE_FREE(&new_state); return retval; } diff --git a/TSRM/tsrm_virtual_cwd.h b/TSRM/tsrm_virtual_cwd.h index 6d2a51e4661..2ecc01c0047 100644 --- a/TSRM/tsrm_virtual_cwd.h +++ b/TSRM/tsrm_virtual_cwd.h @@ -54,7 +54,7 @@ typedef unsigned short mode_t; (*(c) == '\\' && !IsDBCSLeadByte(*(c-1)))) /* COPY_WHEN_ABSOLUTE also takes path as argument because netware needs it -/* to account for volume name that is unique to NetWare absolute paths + * to account for volume name that is unique to NetWare absolute paths */ #define COPY_WHEN_ABSOLUTE(path) 2 #define IS_ABSOLUTE_PATH(path, len) \ @@ -144,7 +144,6 @@ CWD_API int virtual_stat(const char *path, struct stat_libc *buf TSRMLS_DC); #endif #if !defined(TSRM_WIN32) && !defined(NETWARE) CWD_API int virtual_lstat(const char *path, struct stat *buf TSRMLS_DC); -CWD_API char *virtual_link(char *buf, size_t size TSRMLS_DC); #endif CWD_API int virtual_unlink(const char *path TSRMLS_DC); CWD_API int virtual_mkdir(const char *pathname, mode_t mode TSRMLS_DC); diff --git a/ext/standard/link.c b/ext/standard/link.c index c612076c7bf..dcafb604eb1 100644 --- a/ext/standard/link.c +++ b/ext/standard/link.c @@ -58,24 +58,22 @@ PHP_FUNCTION(readlink) { zval **filename; char buff[MAXPATHLEN]; - char *p; int ret; - + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string_ex(filename); - p = virtual_link(Z_STRVAL_PP(filename), Z_STRLEN_PP(filename) TSRMLS_CC); + ret = readlink(Z_STRVAL_PP(filename), buff, MAXPATHLEN-1); - ret = readlink(p, buff, MAXPATHLEN-1); if (ret == -1) { php_error(E_WARNING, "readlink failed (%s)", strerror(errno)); RETURN_FALSE; } /* Append NULL to the end of the string */ buff[ret] = '\0'; - + RETURN_STRING(buff, 1); } /* }}} */