From: Rui Hirokawa Date: Thu, 25 Apr 2002 14:52:58 +0000 (+0000) Subject: fixed directory access problem when direcory name is encoded in japanese Shift_JIS... X-Git-Tag: php-4.2.1RC1~28 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=53da6945423a4dd1df7f2db93793e31ee5947e59;p=php fixed directory access problem when direcory name is encoded in japanese Shift_JIS encoding. --- diff --git a/TSRM/tsrm_virtual_cwd.c b/TSRM/tsrm_virtual_cwd.c index 9c1a5d2925..1712a9c2d8 100644 --- a/TSRM/tsrm_virtual_cwd.c +++ b/TSRM/tsrm_virtual_cwd.c @@ -364,7 +364,8 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func state->cwd = (char *) realloc(state->cwd, state->cwd_length+ptr_length+1+1); #ifdef TSRM_WIN32 /* Windows 9x will consider C:\\Foo as a network path. Avoid it. */ - if (state->cwd[state->cwd_length-1]!='\\' && state->cwd[state->cwd_length-1]!='/') { + if ((state->cwd[state->cwd_length-1]!='\\' && state->cwd[state->cwd_length-1]!='/') || + IsDBCSLeadByte(state->cwd[state->cwd_length-2])) { state->cwd[state->cwd_length++] = DEFAULT_SLASH; } #else diff --git a/TSRM/tsrm_virtual_cwd.h b/TSRM/tsrm_virtual_cwd.h index 52afebe0da..98efaa1432 100644 --- a/TSRM/tsrm_virtual_cwd.h +++ b/TSRM/tsrm_virtual_cwd.h @@ -50,6 +50,8 @@ typedef unsigned short mode_t; #define DEFAULT_SLASH '\\' #define DEFAULT_DIR_SEPARATOR ';' #define IS_SLASH(c) ((c) == '/' || (c) == '\\') +#define IS_SLASH_P(c) (*(c) == '/' || \ + (*(c) == '\\' && !IsDBCSLeadByte(*(c-1)))) #define COPY_WHEN_ABSOLUTE 2 #define IS_ABSOLUTE_PATH(path, len) \ (len >= 2 && isalpha(path[0]) && path[1] == ':') @@ -70,6 +72,7 @@ typedef unsigned short mode_t; #endif #define IS_SLASH(c) ((c) == '/') +#define IS_SLASH_P(c) (*(c) == '/') #endif diff --git a/ext/standard/string.c b/ext/standard/string.c index f68158dd77..94c5512a59 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -1051,7 +1051,7 @@ PHPAPI char *php_basename(char *s, size_t len, char *suffix, size_t sufflen) /* strip trailing slashes */ while (*c == '/' #ifdef PHP_WIN32 - || *c == '\\' + || (*c == '\\' && !IsDBCSLeadByte(*(c-1))) #endif ) c--; @@ -1063,7 +1063,7 @@ PHPAPI char *php_basename(char *s, size_t len, char *suffix, size_t sufflen) if ((c = strrchr(s, '/')) #ifdef PHP_WIN32 - || (c = strrchr(s, '\\')) + || ((c = strrchr(s, '\\')) && !IsDBCSLeadByte(*(c-1))) #endif ) { ret = estrdup(c + 1); @@ -1108,7 +1108,7 @@ PHPAPI void php_dirname(char *path, int len) } /* Strip trailing slashes */ - while (end >= path && IS_SLASH(*end)) { + while (end >= path && IS_SLASH_P(end)) { end--; } if (end < path) { @@ -1119,7 +1119,7 @@ PHPAPI void php_dirname(char *path, int len) } /* Strip filename */ - while (end >= path && !IS_SLASH(*end)) { + while (end >= path && !IS_SLASH_P(end)) { end--; } if (end < path) { @@ -1130,7 +1130,7 @@ PHPAPI void php_dirname(char *path, int len) } /* Strip slashes which came before the file name */ - while (end >= path && IS_SLASH(*end)) { + while (end >= path && IS_SLASH_P(end)) { end--; } if (end < path) {