]> granicus.if.org Git - php/commitdiff
fixed directory access problem when direcory name is encoded in japanese Shift_JIS...
authorRui Hirokawa <hirokawa@php.net>
Thu, 25 Apr 2002 14:52:58 +0000 (14:52 +0000)
committerRui Hirokawa <hirokawa@php.net>
Thu, 25 Apr 2002 14:52:58 +0000 (14:52 +0000)
TSRM/tsrm_virtual_cwd.c
TSRM/tsrm_virtual_cwd.h
ext/standard/string.c

index 9c1a5d29256dfd128073590ab426d89e05fdc86e..1712a9c2d80171f83b1bcb2f75347488df97814f 100644 (file)
@@ -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
index 52afebe0dac1299c6d494ebc1caa802e893a1617..98efaa14323209fbf9db752e1037f14b310a8184 100644 (file)
@@ -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
 
index f68158dd775ed6615b3483797ccc5c05e57fd49f..94c5512a59a6bff9d4e377f7022c16c80ccd7bed 100644 (file)
@@ -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) {