php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | |
Patch php54_dbcs_win_is_slash_2 for Filesystem function related Bug #61315Patch version 2012-03-08 07:38 UTC Return to Bug #61315 | Download this patchThis patch renders other patches obsolete Obsolete patches: Patch Revisions:Developer: ku@digitaldolphins.jpIndex: TSRM/tsrm_virtual_cwd.c =================================================================== --- TSRM/tsrm_virtual_cwd.c (revision 324008) +++ TSRM/tsrm_virtual_cwd.c (working copy) @@ -389,6 +389,30 @@ return 0; } /* }}} */ + +static int is_dbcs_lead_byte_at(const char *str_start, int byte_offset) /* {{{ */ +{ + int x = 0; + char c; + + while (1) { + if (x == byte_offset) + return 1; // yes + c = str_start[x]; + if (c == 0) + break; // null term + if (IsDBCSLeadByte(c)) { + ++x; + c = str_start[x]; + if (c == 0) + break; // null term + } + ++x; + } + return 0; // no +} + /* }}} */ + #endif static int php_is_dir_ok(const cwd_state *state) /* {{{ */ @@ -767,7 +791,7 @@ } i = len; - while (i > start && !IS_SLASH(path[i-1])) { + while (i > start && !IS_SLASH_PI(path, i-1)) { i--; } @@ -789,20 +813,20 @@ j = tsrm_realpath_r(path, start, i-1, ll, t, use_realpath, 1, NULL TSRMLS_CC); if (j > start) { j--; - while (j > start && !IS_SLASH(path[j])) { + while (j > start && !IS_SLASH_PI(path, j)) { j--; } if (!start) { /* leading '..' must not be removed in case of relative path */ if (j == 0 && path[0] == '.' && path[1] == '.' && - IS_SLASH(path[2])) { + IS_SLASH_PI(path, 2)) { path[3] = '.'; path[4] = '.'; path[5] = DEFAULT_SLASH; j = 5; } else if (j > 0 && path[j+1] == '.' && path[j+2] == '.' && - IS_SLASH(path[j+3])) { + IS_SLASH_PI(path, j+3)) { j += 4; path[j++] = '.'; path[j++] = '.'; @@ -1179,25 +1203,25 @@ int state_cwd_length = state->cwd_length; #ifdef TSRM_WIN32 - if (IS_SLASH(path[0])) { + if (IS_SLASH_PI(path, 0)) { 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])) { + while (IS_SLASH_PI(state->cwd, state_cwd_length)) { state_cwd_length++; } while (state->cwd[state_cwd_length] && - !IS_SLASH(state->cwd[state_cwd_length])) { + !IS_SLASH_PI(state->cwd, state_cwd_length)) { state_cwd_length++; } - while (IS_SLASH(state->cwd[state_cwd_length])) { + while (IS_SLASH_PI(state->cwd, state_cwd_length)) { state_cwd_length++; } while (state->cwd[state_cwd_length] && - !IS_SLASH(state->cwd[state_cwd_length])) { + !IS_SLASH_PI(state->cwd, state_cwd_length)) { state_cwd_length++; } } @@ -1218,7 +1242,7 @@ } } else { #ifdef TSRM_WIN32 - if (path_length > 2 && path[1] == ':' && !IS_SLASH(path[2])) { + if (path_length > 2 && path[1] == ':' && !IS_SLASH_PI(path, 2)) { resolved_path[0] = path[0]; resolved_path[1] = ':'; resolved_path[2] = DEFAULT_SLASH; @@ -1242,20 +1266,20 @@ resolved_path[0] = DEFAULT_SLASH; resolved_path[1] = DEFAULT_SLASH; start = 2; - while (!IS_SLASH(resolved_path[start])) { + while (!IS_SLASH_PI(resolved_path, start)) { if (resolved_path[start] == 0) { goto verify; } resolved_path[start] = toupper(resolved_path[start]); - start++; + start += _mbsinc(&resolved_path[start]) - &resolved_path[start]; } resolved_path[start++] = DEFAULT_SLASH; - while (!IS_SLASH(resolved_path[start])) { + while (!IS_SLASH_PI(resolved_path, start)) { if (resolved_path[start] == 0) { goto verify; } resolved_path[start] = toupper(resolved_path[start]); - start++; + start += _mbsinc(&resolved_path[start]) - &resolved_path[start]; } resolved_path[start++] = DEFAULT_SLASH; } else if (IS_ABSOLUTE_PATH(resolved_path, path_length)) { @@ -1268,17 +1292,17 @@ if (IS_ABSOLUTE_PATH(resolved_path, path_length)) { /* skip VOLUME name */ start = 0; - while (start != ':') { + while (resolved_path[start] != ':') { if (resolved_path[start] == 0) return -1; start++; } start++; - if (!IS_SLASH(resolved_path[start])) return -1; + if (!IS_SLASH_PI(resolved_path, start)) return -1; resolved_path[start++] = DEFAULT_SLASH; } #endif - add_slash = (use_realpath != CWD_REALPATH) && path_length > 0 && IS_SLASH(resolved_path[path_length-1]); + add_slash = (use_realpath != CWD_REALPATH) && path_length > 0 && IS_SLASH_PI(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); @@ -1290,7 +1314,7 @@ if (!start && !path_length) { resolved_path[path_length++] = '.'; } - if (add_slash && path_length && !IS_SLASH(resolved_path[path_length-1])) { + if (add_slash && path_length && !IS_SLASH_PI(resolved_path, path_length-1)) { if (path_length >= MAXPATHLEN-1) { return -1; } @@ -1363,7 +1387,7 @@ if (length == 0) { return 1; /* Can't cd to empty string */ } - while(--length >= 0 && !IS_SLASH(path[length])) { + while(--length >= 0 && !IS_SLASH_PI(path, length)) { } if (length == -1) { Index: TSRM/tsrm_virtual_cwd.h =================================================================== --- TSRM/tsrm_virtual_cwd.h (revision 324008) +++ TSRM/tsrm_virtual_cwd.h (working copy) @@ -63,6 +63,7 @@ #define IS_SLASH(c) ((c) == '/' || (c) == '\\') #define IS_SLASH_P(c) (*(c) == '/' || \ (*(c) == '\\' && !IsDBCSLeadByte(*(c-1)))) +#define IS_SLASH_PI(c,i) (IS_SLASH((c)[i]) && is_dbcs_lead_byte_at(c,i)) /* COPY_WHEN_ABSOLUTE is 2 under Win32 because by chance both regular absolute paths in the file system and UNC paths need copying of two characters */ @@ -81,6 +82,7 @@ #define DEFAULT_DIR_SEPARATOR ';' #define IS_SLASH(c) ((c) == '/' || (c) == '\\') #define IS_SLASH_P(c) IS_SLASH(*(c)) +#define IS_SLASH_PI(c,i) IS_SLASH((c)[i]) // untested! /* Colon indicates volume name, either first character should be forward slash or backward slash */ #define IS_ABSOLUTE_PATH(path, len) \ ((strchr(path, ':') != NULL) || ((len >= 1) && ((path[0] == '/') || (path[0] == '\\')))) @@ -100,6 +102,7 @@ #define IS_SLASH(c) ((c) == '/') #define IS_SLASH_P(c) (*(c) == '/') +#define IS_SLASH_PI(c,i) ((c)[i] == '/') // untested! #endif |
Copyright © 2001-2024 The PHP Group All rights reserved. |
Last updated: Sat Nov 23 10:01:28 2024 UTC |