From 494f56c870fd7ea7c1f1c8a1308689b0ea23bc09 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 21 Jan 2009 19:11:50 +0000 Subject: [PATCH] Fixed realpath() behavior to support "c:dir" as "c:\dir", and "\dir" on UNC CWD --- TSRM/tsrm_virtual_cwd.c | 34 +++++++++++++++++-- .../tests/file/fopen_variation10-win32.phpt | 6 +--- .../tests/file/fopen_variation11-win32.phpt | 6 +--- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/TSRM/tsrm_virtual_cwd.c b/TSRM/tsrm_virtual_cwd.c index d466bac8a1..2987efb154 100644 --- a/TSRM/tsrm_virtual_cwd.c +++ b/TSRM/tsrm_virtual_cwd.c @@ -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; } diff --git a/ext/standard/tests/file/fopen_variation10-win32.phpt b/ext/standard/tests/file/fopen_variation10-win32.phpt index 0c0d25b6db..2ad817c4fb 100644 --- a/ext/standard/tests/file/fopen_variation10-win32.phpt +++ b/ext/standard/tests/file/fopen_variation10-win32.phpt @@ -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-- diff --git a/ext/standard/tests/file/fopen_variation11-win32.phpt b/ext/standard/tests/file/fopen_variation11-win32.phpt index f50adb8cc5..80307fddcc 100644 --- a/ext/standard/tests/file/fopen_variation11-win32.phpt +++ b/ext/standard/tests/file/fopen_variation11-win32.phpt @@ -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-- -- 2.50.1