]> granicus.if.org Git - php/commitdiff
Fixed realpath() behavior to support "c:dir" as "c:\dir", and "\dir" on UNC CWD
authorDmitry Stogov <dmitry@php.net>
Wed, 21 Jan 2009 19:11:50 +0000 (19:11 +0000)
committerDmitry Stogov <dmitry@php.net>
Wed, 21 Jan 2009 19:11:50 +0000 (19:11 +0000)
TSRM/tsrm_virtual_cwd.c
ext/standard/tests/file/fopen_variation10-win32.phpt
ext/standard/tests/file/fopen_variation11-win32.phpt

index d466bac8a11cd7b8e36f9145aab0c57498b42a38..2987efb154c9cc801613f7ff358d051639f26d94 100644 (file)
@@ -755,7 +755,27 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
 
 #ifdef TSRM_WIN32
                        if (IS_SLASH(path[0])) {
-                               state_cwd_length = 2;
+                               if (state->cwd[1] == ':') {
+                                       /* Copy only the drive name */
+                                       state_cwd_length = 2;
+                               } else if (IS_UNC_PATH(state->cwd, state->cwd_length)) {
+                                       /* Copy only the share name */
+                                       state_cwd_length = 2;
+                                       while (IS_SLASH(state->cwd[state_cwd_length])) {
+                                               state_cwd_length++;
+                                       }                                                
+                                       while (state->cwd[state_cwd_length] &&
+                                              !IS_SLASH(state->cwd[state_cwd_length])) {
+                                               state_cwd_length++;
+                                       }                                                
+                                       while (IS_SLASH(state->cwd[state_cwd_length])) {
+                                               state_cwd_length++;
+                                       }                                                
+                                       while (state->cwd[state_cwd_length] &&
+                                              !IS_SLASH(state->cwd[state_cwd_length])) {
+                                               state_cwd_length++;
+                                       }                                                
+                               }
                        }
 #endif
                        if (path_length + state_cwd_length + 1 >= MAXPATHLEN-1) {
@@ -767,7 +787,16 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
                        path_length += state_cwd_length + 1;
                }
        } else {                
-               memcpy(resolved_path , path, path_length + 1);
+#ifdef TSRM_WIN32
+               if (path_length > 2 && path[1] == ':' && !IS_SLASH(path[2])) {
+                       resolved_path[0] = path[0];
+                       resolved_path[1] = ':';
+                       resolved_path[2] = DEFAULT_SLASH;
+                       memcpy(resolved_path + 3, path + 2, path_length - 1);
+                       path_length++;
+               } else
+#endif
+               memcpy(resolved_path, path, path_length + 1);
        } 
 
 #ifdef TSRM_WIN32
@@ -824,6 +853,7 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
        path_length = tsrm_realpath_r(resolved_path, start, path_length, &ll, &t, use_realpath, 0, NULL TSRMLS_CC);
        
        if (path_length < 0) {
+               errno = ENOENT;
                return 1;
        }
        
index 0c0d25b6dbbc71249b65c3d501df4adc2ec7f60d..2ad817c4fb435caa81492f227416d3dc79620e8b 100644 (file)
@@ -112,11 +112,7 @@ file not opened for read
 Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d
 
 --c:fopen10.tmpdirTwo--
-
-Warning: fopen(c:fopen10.tmpdirTwo\fopen_variation10.tmp): failed to open stream: No such file or directory in %s on line %d
-file not opened for read
-
-Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d
+file in fopen10.tmpdirTwo
 
 --c:adir--
 
index f50adb8cc5bfb781684b4ec9e9b97bed6b9639d3..80307fddccec9c99880c9a698982203ca4b4ce43 100644 (file)
@@ -111,11 +111,7 @@ file not opened for read
 Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d
 
 --c:fopen11.tmpdirTwo--
-
-Warning: fopen(c:fopen11.tmpdirTwo\fopen_variation11.tmp): failed to open stream: No such file or directory in %s on line %d
-file not opened for read
-
-Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d
+file in fopen11.tmpdirTwo
 
 --c:adir--