diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-04-14 00:34:32 +0200 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-04-20 19:14:40 +0200 |
commit | 09143ee49a2f51596adad443b394e9bd5a98ecf1 (patch) | |
tree | 5c53b8fdcc1e82cafc8891dc6e6ec555f0572ed4 /shell | |
parent | 79deabdfb47409f31d0f6ea044b92e8eac09cec2 (diff) | |
download | busybox-w32-09143ee49a2f51596adad443b394e9bd5a98ecf1.tar.gz busybox-w32-09143ee49a2f51596adad443b394e9bd5a98ecf1.tar.bz2 busybox-w32-09143ee49a2f51596adad443b394e9bd5a98ecf1.zip |
win32: ash: new implementation for updatepwd()
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/shell/ash.c b/shell/ash.c index 8df1a4062..a0c22689f 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -2392,6 +2392,98 @@ cdopt(void) | |||
2392 | static const char * | 2392 | static const char * |
2393 | updatepwd(const char *dir) | 2393 | updatepwd(const char *dir) |
2394 | { | 2394 | { |
2395 | #if ENABLE_PLATFORM_MINGW32 | ||
2396 | /* | ||
2397 | * Due to Windows drive notion, getting pwd is a completely | ||
2398 | * different thing. Handle it in a separate routine | ||
2399 | */ | ||
2400 | |||
2401 | char *new; | ||
2402 | char *p; | ||
2403 | char *cdcomppath; | ||
2404 | const char *lim; | ||
2405 | /* | ||
2406 | * There are four cases | ||
2407 | * absdrive + abspath: c:/path | ||
2408 | * absdrive + !abspath: c:path | ||
2409 | * !absdrive + abspath: /path | ||
2410 | * !absdrive + !abspath: path | ||
2411 | * | ||
2412 | * Damn DOS! | ||
2413 | * c:path behaviour is "undefined" | ||
2414 | * To properly handle this case, I have to keep track of cwd | ||
2415 | * of every drive, which is too painful to do. | ||
2416 | * So when c:path is given, I assume it's c:${curdir}path | ||
2417 | * with ${curdir} comes from the current drive | ||
2418 | */ | ||
2419 | int absdrive = *dir && dir[1] == ':'; | ||
2420 | int abspath = absdrive ? dir[2] == '/' : *dir == '/'; | ||
2421 | char *drive; | ||
2422 | |||
2423 | cdcomppath = ststrdup(dir); | ||
2424 | STARTSTACKSTR(new); | ||
2425 | if (!absdrive && curdir == nullstr) | ||
2426 | return 0; | ||
2427 | if (!abspath) { | ||
2428 | if (curdir == nullstr) | ||
2429 | return 0; | ||
2430 | new = stack_putstr(curdir, new); | ||
2431 | } | ||
2432 | new = makestrspace(strlen(dir) + 2, new); | ||
2433 | |||
2434 | drive = stackblock(); | ||
2435 | if (absdrive) { | ||
2436 | *drive = *dir; | ||
2437 | cdcomppath += 2; | ||
2438 | dir += 2; | ||
2439 | } else { | ||
2440 | *drive = *curdir; | ||
2441 | } | ||
2442 | drive[1] = ':'; /* in case of absolute drive+path */ | ||
2443 | |||
2444 | if (abspath) | ||
2445 | new = drive + 2; | ||
2446 | lim = drive + 3; | ||
2447 | if (!abspath) { | ||
2448 | if (new[-1] != '/') | ||
2449 | USTPUTC('/', new); | ||
2450 | if (new > lim && *lim == '/') | ||
2451 | lim++; | ||
2452 | } else { | ||
2453 | USTPUTC('/', new); | ||
2454 | cdcomppath ++; | ||
2455 | if (dir[1] == '/' && dir[2] != '/') { | ||
2456 | USTPUTC('/', new); | ||
2457 | cdcomppath++; | ||
2458 | lim++; | ||
2459 | } | ||
2460 | } | ||
2461 | p = strtok(cdcomppath, "/"); | ||
2462 | while (p) { | ||
2463 | switch (*p) { | ||
2464 | case '.': | ||
2465 | if (p[1] == '.' && p[2] == '\0') { | ||
2466 | while (new > lim) { | ||
2467 | STUNPUTC(new); | ||
2468 | if (new[-1] == '/') | ||
2469 | break; | ||
2470 | } | ||
2471 | break; | ||
2472 | } | ||
2473 | if (p[1] == '\0') | ||
2474 | break; | ||
2475 | /* fall through */ | ||
2476 | default: | ||
2477 | new = stack_putstr(p, new); | ||
2478 | USTPUTC('/', new); | ||
2479 | } | ||
2480 | p = strtok(0, "/"); | ||
2481 | } | ||
2482 | if (new > lim) | ||
2483 | STUNPUTC(new); | ||
2484 | *new = 0; | ||
2485 | return stackblock(); | ||
2486 | #else | ||
2395 | char *new; | 2487 | char *new; |
2396 | char *p; | 2488 | char *p; |
2397 | char *cdcomppath; | 2489 | char *cdcomppath; |
@@ -2445,6 +2537,7 @@ updatepwd(const char *dir) | |||
2445 | STUNPUTC(new); | 2537 | STUNPUTC(new); |
2446 | *new = 0; | 2538 | *new = 0; |
2447 | return stackblock(); | 2539 | return stackblock(); |
2540 | #endif | ||
2448 | } | 2541 | } |
2449 | 2542 | ||
2450 | /* | 2543 | /* |