From eb28f737c24d7ff3bb3d6407f5aacb7bd62b6edf Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Date: Fri, 14 Jan 2011 20:23:55 +0700 Subject: win32: ash: teach "cd" DOS path separator '\' docd() is rewritten to deal with DOS paths. Surprisingly, I did not consider '\' as path separator, only '/'. Teach it to see '\' just like '/'. Should fix github issue 3. --- shell/ash.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/shell/ash.c b/shell/ash.c index f7baf2b3b..bc7e005ab 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -2566,6 +2566,7 @@ static const char * updatepwd(const char *dir) { #if ENABLE_PLATFORM_MINGW32 +#define is_path_sep(x) ((x) == '/' || (x) == '\\') /* * Due to Windows drive notion, getting pwd is a completely * different thing. Handle it in a separate routine @@ -2590,7 +2591,7 @@ updatepwd(const char *dir) * with ${curdir} comes from the current drive */ int absdrive = *dir && dir[1] == ':'; - int abspath = absdrive ? dir[2] == '/' : *dir == '/'; + int abspath = absdrive ? is_path_sep(dir[2]) : is_path_sep(*dir); char *drive; cdcomppath = ststrdup(dir); @@ -2618,27 +2619,27 @@ updatepwd(const char *dir) new = drive + 2; lim = drive + 3; if (!abspath) { - if (new[-1] != '/') + if (!is_path_sep(new[-1])) USTPUTC('/', new); - if (new > lim && *lim == '/') + if (new > lim && is_path_sep(*lim)) lim++; } else { USTPUTC('/', new); cdcomppath ++; - if (dir[1] == '/' && dir[2] != '/') { + if (is_path_sep(dir[1]) && !is_path_sep(dir[2])) { USTPUTC('/', new); cdcomppath++; lim++; } } - p = strtok(cdcomppath, "/"); + p = strtok(cdcomppath, "/\\"); while (p) { switch (*p) { case '.': if (p[1] == '.' && p[2] == '\0') { while (new > lim) { STUNPUTC(new); - if (new[-1] == '/') + if (is_path_sep(new[-1])) break; } break; @@ -2650,7 +2651,7 @@ updatepwd(const char *dir) new = stack_putstr(p, new); USTPUTC('/', new); } - p = strtok(0, "/"); + p = strtok(0, "/\\"); } if (new > lim) STUNPUTC(new); -- cgit v1.2.3-55-g6feb