]> granicus.if.org Git - php/commitdiff
VCWD_REALPATH() is improved to use realpath cache without VIRTUAL_DIR
authorDmitry Stogov <dmitry@php.net>
Fri, 10 Nov 2006 12:59:41 +0000 (12:59 +0000)
committerDmitry Stogov <dmitry@php.net>
Fri, 10 Nov 2006 12:59:41 +0000 (12:59 +0000)
TSRM/tsrm_virtual_cwd.c
TSRM/tsrm_virtual_cwd.h

index eafa003aecddf96406609c5daf19a1ac58a8a6d0..30c83f06cf9020a679cced53a235933ce56aef02 100644 (file)
@@ -1033,25 +1033,36 @@ CWD_API FILE *virtual_popen(const char *command, const char *type TSRMLS_DC)
 
 #endif
 
-/* On AIX & Tru64 when a file does not exist realpath() returns
- * NULL, and sets errno to ENOENT. Unlike in other libc implementations
- * the destination is not filled and remains undefined. Therefor, we
- * must populate it manually using strcpy as done on systems with no
- * realpath() function.
- */
-#if defined(__osf__) || defined(_AIX)
-char *php_realpath_hack(const char *src, char *dest)
+CWD_API char *tsrm_realpath(const char *path, char *real_path TSRMLS_DC)
 {
-       char *ret;
+       cwd_state new_state;
+       char cwd[MAXPATHLEN];
 
-       if ((ret = realpath(src, dest)) == NULL && errno == ENOENT) {
-               return strcpy(dest, src);
+       if (!IS_ABSOLUTE_PATH(path, strlen(path)) &&
+           VCWD_GETCWD(cwd, MAXPATHLEN)) {
+               new_state.cwd = strdup(cwd);
+               new_state.cwd_length = strlen(cwd);
        } else {
-               return ret;
+               new_state.cwd = (char*)malloc(1);
+               new_state.cwd[0] = '\0';
+               new_state.cwd_length = 0;               
+       }
+
+       if (virtual_file_ex(&new_state, path, NULL, 1)) {
+               free(new_state.cwd);
+               return NULL;
        }
-}
-#endif
 
+       if (real_path) {
+               int copy_len = new_state.cwd_length>MAXPATHLEN-1 ? MAXPATHLEN-1 : new_state.cwd_length;
+               memcpy(real_path, new_state.cwd, copy_len);
+               real_path[copy_len] = '\0';
+               free(new_state.cwd);
+               return real_path;
+       } else {
+               return new_state.cwd;
+       }
+}
 
 
 /*
index f51677e8dcdbfda46672c293ad364bc19c4ca918..e4f63afa7e58007fcf852aebcac0b5fb4fb67509 100644 (file)
@@ -189,10 +189,6 @@ CWD_API int virtual_access(const char *pathname, int mode TSRMLS_DC);
 #endif
 #endif
 
-#if defined(__osf__) || defined(_AIX)
-char *php_realpath_hack(const char *src, char *dest);
-#endif
-
 #if HAVE_UTIME
 CWD_API int virtual_utime(const char *filename, struct utimbuf *buf TSRMLS_DC);
 #endif
@@ -203,6 +199,8 @@ CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group, int li
 
 CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path, int use_realpath);
 
+CWD_API char *tsrm_realpath(const char *path, char *real_path TSRMLS_DC);
+
 #define REALPATH_CACHE_TTL  (2*60) /* 2 minutes */
 #define REALPATH_CACHE_SIZE 0      /* disabled while php.ini isn't loaded */
 
@@ -295,15 +293,7 @@ extern virtual_cwd_globals cwd_globals;
 #define VCWD_ACCESS(pathname, mode) access(pathname, mode)
 #endif
 
-#ifdef HAVE_REALPATH
-#if defined(__osf__) || defined(_AIX)
-#define VCWD_REALPATH(path, real_path) php_realpath_hack(path, real_path)
-#else
-#define VCWD_REALPATH(path, real_path) realpath(path, real_path)
-#endif
-#else
-#define VCWD_REALPATH(path, real_path) strcpy(real_path, path)
-#endif
+#define VCWD_REALPATH(path, real_path) tsrm_realpath(path, real_path TSRMLS_CC)
 
 #if HAVE_UTIME
 #define VCWD_UTIME(path, time) utime(path, time)