diff options
author | Pierre Joye <pajoye@php.net> | 2010-09-10 14:02:19 +0000 |
---|---|---|
committer | Pierre Joye <pajoye@php.net> | 2010-09-10 14:02:19 +0000 |
commit | ae5044126657f6024b14002687fe8ec9ab0c2979 (patch) | |
tree | 904103af45a807d2b2b0488104ad264b61f3f894 /TSRM | |
parent | bf0a5ea7452032ca09d71835c548d9d5db398850 (diff) | |
download | php-git-ae5044126657f6024b14002687fe8ec9ab0c2979.tar.gz |
- WS
Diffstat (limited to 'TSRM')
-rw-r--r-- | TSRM/tsrm_virtual_cwd.c | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/TSRM/tsrm_virtual_cwd.c b/TSRM/tsrm_virtual_cwd.c index 25d56f2a80..1f115f6646 100644 --- a/TSRM/tsrm_virtual_cwd.c +++ b/TSRM/tsrm_virtual_cwd.c @@ -88,14 +88,14 @@ cwd_state main_cwd_state; /* True global */ #include <tchar.h> #define tsrm_strtok_r(a,b,c) _tcstok((a),(b)) #define TOKENIZER_STRING "/\\" - -static int php_check_dots(const char *element, int n) + +static int php_check_dots(const char *element, int n) { while (n-- > 0) if (element[n] != '.') break; return (n != -1); } - + #define IS_DIRECTORY_UP(element, len) \ (len >= 2 && !php_check_dots(element, len)) @@ -129,7 +129,7 @@ static int php_check_dots(const char *element, int n) /* define this to check semantics */ #define IS_DIR_OK(s) (1) - + #ifndef IS_DIR_OK #define IS_DIR_OK(state) (php_is_dir_ok(state) == 0) #endif @@ -142,7 +142,7 @@ static int php_check_dots(const char *element, int n) #define CWD_STATE_FREE(s) \ free((s)->cwd); - + #ifdef TSRM_WIN32 #ifdef CTL_CODE @@ -249,7 +249,7 @@ CWD_API int php_sys_readlink(const char *link, char *target, size_t target_len){ /* 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); @@ -428,7 +428,7 @@ CWD_API void virtual_cwd_startup(void) /* {{{ */ } } #else - result = getcwd(cwd, sizeof(cwd)); + result = getcwd(cwd, sizeof(cwd)); #endif if (!result) { cwd[0] = '\0'; @@ -479,7 +479,7 @@ CWD_API char *virtual_getcwd_ex(size_t *length TSRMLS_DC) /* {{{ */ *length = 1; retval = (char *) malloc(2); retval[0] = DEFAULT_SLASH; - retval[1] = '\0'; + retval[1] = '\0'; return retval; } @@ -606,7 +606,7 @@ static inline void realpath_cache_add(const char *path, int path_len, const char { long size = sizeof(realpath_cache_bucket) + path_len + 1; int same = 1; - + if (realpath_len != path_len || memcmp(path, realpath, path_len) != 0) { size += realpath_len + 1; @@ -682,17 +682,17 @@ CWD_API realpath_cache_bucket* realpath_cache_lookup(const char *path, int path_ } /* }}} */ -CWD_API int realpath_cache_size(TSRMLS_D) +CWD_API int realpath_cache_size(TSRMLS_D) { return CWDG(realpath_cache_size); } -CWD_API int realpath_cache_max_buckets(TSRMLS_D) +CWD_API int realpath_cache_max_buckets(TSRMLS_D) { return (sizeof(CWDG(realpath_cache)) / sizeof(CWDG(realpath_cache)[0])); } -CWD_API realpath_cache_bucket** realpath_cache_get_buckets(TSRMLS_D) +CWD_API realpath_cache_bucket** realpath_cache_get_buckets(TSRMLS_D) { return CWDG(realpath_cache); } @@ -751,7 +751,7 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i path[4] = '.'; path[5] = DEFAULT_SLASH; j = 5; - } else if (j > 0 && + } else if (j > 0 && path[j+1] == '.' && path[j+2] == '.' && IS_SLASH(path[j+3])) { j += 4; @@ -769,7 +769,7 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i } return j; } - + path[len] = 0; save = (use_realpath != CWD_EXPAND); @@ -802,7 +802,7 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i /* continue resolution anyway but don't save result in the cache */ save = 0; } - + if (save) { FindClose(hFind); } @@ -810,7 +810,7 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i 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 */ @@ -847,7 +847,7 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i reparsetarget = pbuffer->SymbolicLinkReparseBuffer.ReparseTarget; printname_len = pbuffer->MountPointReparseBuffer.PrintNameLength / sizeof(WCHAR); isabsolute = (pbuffer->SymbolicLinkReparseBuffer.Flags == 0) ? 1 : 0; - if (!WideCharToMultiByte(CP_THREAD_ACP, 0, + if (!WideCharToMultiByte(CP_THREAD_ACP, 0, reparsetarget + pbuffer->MountPointReparseBuffer.PrintNameOffset / sizeof(WCHAR), printname_len + 1, printname, MAX_PATH, NULL, NULL @@ -859,7 +859,7 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i printname[printname_len] = 0; substitutename_len = pbuffer->MountPointReparseBuffer.SubstituteNameLength / sizeof(WCHAR); - if (!WideCharToMultiByte(CP_THREAD_ACP, 0, + if (!WideCharToMultiByte(CP_THREAD_ACP, 0, reparsetarget + pbuffer->MountPointReparseBuffer.SubstituteNameOffset / sizeof(WCHAR), substitutename_len + 1, substitutename, MAX_PATH, NULL, NULL @@ -873,7 +873,7 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i isabsolute = 1; reparsetarget = pbuffer->MountPointReparseBuffer.ReparseTarget; printname_len = pbuffer->MountPointReparseBuffer.PrintNameLength / sizeof(WCHAR); - if (!WideCharToMultiByte(CP_THREAD_ACP, 0, + if (!WideCharToMultiByte(CP_THREAD_ACP, 0, reparsetarget + pbuffer->MountPointReparseBuffer.PrintNameOffset / sizeof(WCHAR), printname_len + 1, printname, MAX_PATH, NULL, NULL @@ -884,7 +884,7 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i printname[pbuffer->MountPointReparseBuffer.PrintNameLength / sizeof(WCHAR)] = 0; substitutename_len = pbuffer->MountPointReparseBuffer.SubstituteNameLength / sizeof(WCHAR); - if (!WideCharToMultiByte(CP_THREAD_ACP, 0, + if (!WideCharToMultiByte(CP_THREAD_ACP, 0, reparsetarget + pbuffer->MountPointReparseBuffer.SubstituteNameOffset / sizeof(WCHAR), substitutename_len + 1, substitutename, MAX_PATH, NULL, NULL @@ -899,14 +899,14 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i } if(isabsolute && substitutename_len > 4) { - /* Do not resolve volumes (for now). A mounted point can + /* Do not resolve volumes (for now). A mounted point can target a volume without a drive, it is not certain that - all IO functions we use in php and its deps support + all IO functions we use in php and its deps support path with volume GUID instead of the DOS way, like: d:\test\mnt\foo \\?\Volume{62d1c3f8-83b9-11de-b108-806e6f6e6963}\foo */ - if (strncmp(substitutename, "\\??\\Volume{",11) == 0 + if (strncmp(substitutename, "\\??\\Volume{",11) == 0 || strncmp(substitutename, "\\\\?\\Volume{",11) == 0 || strncmp(substitutename, "\\??\\UNC\\", 8) == 0 ) { @@ -914,7 +914,7 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i substitutename_off = 0; } else /* do not use the \??\ and \\?\ prefix*/ - if (strncmp(substitutename, "\\??\\", 4) == 0 + if (strncmp(substitutename, "\\??\\", 4) == 0 || strncmp(substitutename, "\\\\?\\", 4) == 0) { substitutename_off = 4; } @@ -1135,18 +1135,18 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func 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 @@ -1158,7 +1158,7 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func memcpy(resolved_path + state_cwd_length + 1, path, path_length + 1); path_length += state_cwd_length + 1; } - } else { + } else { #ifdef TSRM_WIN32 if (path_length > 2 && path[1] == ':' && !IS_SLASH(path[2])) { resolved_path[0] = path[0]; @@ -1169,7 +1169,7 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func } else #endif memcpy(resolved_path, path, path_length + 1); - } + } #ifdef TSRM_WIN32 if (memchr(resolved_path, '*', path_length) || @@ -1223,12 +1223,12 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func add_slash = (use_realpath != CWD_REALPATH) && path_length > 0 && IS_SLASH(resolved_path[path_length-1]); t = CWDG(realpath_cache_ttl) ? 0 : -1; 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; } - + if (!start && !path_length) { resolved_path[path_length++] = '.'; } @@ -1281,7 +1281,7 @@ verify: memcpy(state->cwd, resolved_path, state->cwd_length+1); ret = 0; } - + #if VIRTUAL_CWD_DEBUG fprintf (stderr, "virtual_file_ex() = %s\n",state->cwd); #endif @@ -1304,7 +1304,7 @@ CWD_API int virtual_chdir_file(const char *path, int (*p_chdir)(const char *path if (length == 0) { return 1; /* Can't cd to empty string */ - } + } while(--length >= 0 && !IS_SLASH(path[length])) { } @@ -1339,7 +1339,7 @@ CWD_API char *virtual_realpath(const char *path, char *real_path TSRMLS_DC) /* { if (!*path) { new_state.cwd = (char*)malloc(1); new_state.cwd[0] = '\0'; - new_state.cwd_length = 0; + new_state.cwd_length = 0; if (VCWD_GETCWD(cwd, MAXPATHLEN)) { path = cwd; } @@ -1348,7 +1348,7 @@ CWD_API char *virtual_realpath(const char *path, char *real_path TSRMLS_DC) /* { } else { new_state.cwd = (char*)malloc(1); new_state.cwd[0] = '\0'; - new_state.cwd_length = 0; + new_state.cwd_length = 0; } if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH TSRMLS_CC)==0) { @@ -1414,7 +1414,7 @@ CWD_API int virtual_access(const char *pathname, int mode TSRMLS_DC) /* {{{ */ { cwd_state new_state; int ret; - + CWD_STATE_COPY(&new_state, &CWDG(cwd)); if (virtual_file_ex(&new_state, pathname, NULL, CWD_REALPATH TSRMLS_CC)) { CWD_STATE_FREE(&new_state); @@ -1426,9 +1426,9 @@ CWD_API int virtual_access(const char *pathname, int mode TSRMLS_DC) /* {{{ */ #else ret = access(new_state.cwd, mode); #endif - + CWD_STATE_FREE(&new_state); - + return ret; } /* }}} */ @@ -1449,12 +1449,12 @@ static void UnixTimeToFileTime(time_t t, LPFILETIME pft) /* {{{ */ TSRM_API int win32_utime(const char *filename, struct utimbuf *buf) /* {{{ */ { FILETIME mtime, atime; - HANDLE hFile; + HANDLE hFile; hFile = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_WRITE|FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_FLAG_BACKUP_SEMANTICS, NULL); - /* OPEN_ALWAYS mode sets the last error to ERROR_ALREADY_EXISTS but + /* OPEN_ALWAYS mode sets the last error to ERROR_ALREADY_EXISTS but the CreateFile operation succeeds */ if (GetLastError() == ERROR_ALREADY_EXISTS) { SetLastError(0); @@ -1574,7 +1574,7 @@ CWD_API int virtual_open(const char *path TSRMLS_DC, int flags, ...) /* {{{ */ f = open(new_state.cwd, flags, mode); } else { f = open(new_state.cwd, flags); - } + } CWD_STATE_FREE(&new_state); return f; } @@ -1833,7 +1833,7 @@ CWD_API FILE *virtual_popen(const char *command, const char *type TSRMLS_DC) /* } *ptr++ = '\''; } - + *ptr++ = ' '; *ptr++ = ';'; *ptr++ = ' '; @@ -1856,7 +1856,7 @@ CWD_API char *tsrm_realpath(const char *path, char *real_path TSRMLS_DC) /* {{{ if (!*path) { new_state.cwd = (char*)malloc(1); new_state.cwd[0] = '\0'; - new_state.cwd_length = 0; + new_state.cwd_length = 0; if (VCWD_GETCWD(cwd, MAXPATHLEN)) { path = cwd; } @@ -1867,7 +1867,7 @@ CWD_API char *tsrm_realpath(const char *path, char *real_path TSRMLS_DC) /* {{{ } else { new_state.cwd = (char*)malloc(1); new_state.cwd[0] = '\0'; - new_state.cwd_length = 0; + new_state.cwd_length = 0; } if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH TSRMLS_CC)) { |