diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2011-01-14 20:23:55 +0700 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2011-01-14 20:26:08 +0700 |
commit | eb28f737c24d7ff3bb3d6407f5aacb7bd62b6edf (patch) | |
tree | 7cda996cc00729886be8c5a6ec4ccf9913343bda | |
parent | 5f6f2162512106adf120d4b528bb125e93e34429 (diff) | |
download | busybox-w32-eb28f737c24d7ff3bb3d6407f5aacb7bd62b6edf.tar.gz busybox-w32-eb28f737c24d7ff3bb3d6407f5aacb7bd62b6edf.tar.bz2 busybox-w32-eb28f737c24d7ff3bb3d6407f5aacb7bd62b6edf.zip |
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.
-rw-r--r-- | shell/ash.c | 15 |
1 files 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 * | |||
2566 | updatepwd(const char *dir) | 2566 | updatepwd(const char *dir) |
2567 | { | 2567 | { |
2568 | #if ENABLE_PLATFORM_MINGW32 | 2568 | #if ENABLE_PLATFORM_MINGW32 |
2569 | #define is_path_sep(x) ((x) == '/' || (x) == '\\') | ||
2569 | /* | 2570 | /* |
2570 | * Due to Windows drive notion, getting pwd is a completely | 2571 | * Due to Windows drive notion, getting pwd is a completely |
2571 | * different thing. Handle it in a separate routine | 2572 | * different thing. Handle it in a separate routine |
@@ -2590,7 +2591,7 @@ updatepwd(const char *dir) | |||
2590 | * with ${curdir} comes from the current drive | 2591 | * with ${curdir} comes from the current drive |
2591 | */ | 2592 | */ |
2592 | int absdrive = *dir && dir[1] == ':'; | 2593 | int absdrive = *dir && dir[1] == ':'; |
2593 | int abspath = absdrive ? dir[2] == '/' : *dir == '/'; | 2594 | int abspath = absdrive ? is_path_sep(dir[2]) : is_path_sep(*dir); |
2594 | char *drive; | 2595 | char *drive; |
2595 | 2596 | ||
2596 | cdcomppath = ststrdup(dir); | 2597 | cdcomppath = ststrdup(dir); |
@@ -2618,27 +2619,27 @@ updatepwd(const char *dir) | |||
2618 | new = drive + 2; | 2619 | new = drive + 2; |
2619 | lim = drive + 3; | 2620 | lim = drive + 3; |
2620 | if (!abspath) { | 2621 | if (!abspath) { |
2621 | if (new[-1] != '/') | 2622 | if (!is_path_sep(new[-1])) |
2622 | USTPUTC('/', new); | 2623 | USTPUTC('/', new); |
2623 | if (new > lim && *lim == '/') | 2624 | if (new > lim && is_path_sep(*lim)) |
2624 | lim++; | 2625 | lim++; |
2625 | } else { | 2626 | } else { |
2626 | USTPUTC('/', new); | 2627 | USTPUTC('/', new); |
2627 | cdcomppath ++; | 2628 | cdcomppath ++; |
2628 | if (dir[1] == '/' && dir[2] != '/') { | 2629 | if (is_path_sep(dir[1]) && !is_path_sep(dir[2])) { |
2629 | USTPUTC('/', new); | 2630 | USTPUTC('/', new); |
2630 | cdcomppath++; | 2631 | cdcomppath++; |
2631 | lim++; | 2632 | lim++; |
2632 | } | 2633 | } |
2633 | } | 2634 | } |
2634 | p = strtok(cdcomppath, "/"); | 2635 | p = strtok(cdcomppath, "/\\"); |
2635 | while (p) { | 2636 | while (p) { |
2636 | switch (*p) { | 2637 | switch (*p) { |
2637 | case '.': | 2638 | case '.': |
2638 | if (p[1] == '.' && p[2] == '\0') { | 2639 | if (p[1] == '.' && p[2] == '\0') { |
2639 | while (new > lim) { | 2640 | while (new > lim) { |
2640 | STUNPUTC(new); | 2641 | STUNPUTC(new); |
2641 | if (new[-1] == '/') | 2642 | if (is_path_sep(new[-1])) |
2642 | break; | 2643 | break; |
2643 | } | 2644 | } |
2644 | break; | 2645 | break; |
@@ -2650,7 +2651,7 @@ updatepwd(const char *dir) | |||
2650 | new = stack_putstr(p, new); | 2651 | new = stack_putstr(p, new); |
2651 | USTPUTC('/', new); | 2652 | USTPUTC('/', new); |
2652 | } | 2653 | } |
2653 | p = strtok(0, "/"); | 2654 | p = strtok(0, "/\\"); |
2654 | } | 2655 | } |
2655 | if (new > lim) | 2656 | if (new > lim) |
2656 | STUNPUTC(new); | 2657 | STUNPUTC(new); |