diff options
-rw-r--r-- | include/mingw.h | 2 | ||||
-rw-r--r-- | libbb/get_last_path_component.c | 21 |
2 files changed, 22 insertions, 1 deletions
diff --git a/include/mingw.h b/include/mingw.h index 6d494b7ef..196356288 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
@@ -459,7 +459,7 @@ pid_t mingw_spawn_1(int mode, const char *cmd, const char *const *argv, const ch | |||
459 | 459 | ||
460 | const char * next_path_sep(const char *path); | 460 | const char * next_path_sep(const char *path); |
461 | #define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':') | 461 | #define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':') |
462 | #define is_absolute_path(path) ((path)[0] == '/' || has_dos_drive_prefix(path)) | 462 | #define is_absolute_path(path) ((path)[0] == '/' || (path)[0] == '\\' || has_dos_drive_prefix(path)) |
463 | 463 | ||
464 | /* | 464 | /* |
465 | * helpers | 465 | * helpers |
diff --git a/libbb/get_last_path_component.c b/libbb/get_last_path_component.c index db4be68ad..15eb85ca8 100644 --- a/libbb/get_last_path_component.c +++ b/libbb/get_last_path_component.c | |||
@@ -31,8 +31,18 @@ char* FAST_FUNC bb_get_last_path_component_nostrip(const char *path) | |||
31 | { | 31 | { |
32 | char *slash = strrchr(path, '/'); | 32 | char *slash = strrchr(path, '/'); |
33 | 33 | ||
34 | #if ENABLE_PLATFORM_MINGW32 | ||
35 | const char *start = has_dos_drive_prefix(path) ? path+2 : path; | ||
36 | |||
37 | if (!slash) | ||
38 | slash = strrchr(path, '\\'); | ||
39 | |||
40 | if (!slash || (slash == start && !slash[1])) | ||
41 | return (char*)path; | ||
42 | #else | ||
34 | if (!slash || (slash == path && !slash[1])) | 43 | if (!slash || (slash == path && !slash[1])) |
35 | return (char*)path; | 44 | return (char*)path; |
45 | #endif | ||
36 | 46 | ||
37 | return slash + 1; | 47 | return slash + 1; |
38 | } | 48 | } |
@@ -47,9 +57,20 @@ char* FAST_FUNC bb_get_last_path_component_strip(char *path) | |||
47 | { | 57 | { |
48 | char *slash = last_char_is(path, '/'); | 58 | char *slash = last_char_is(path, '/'); |
49 | 59 | ||
60 | #if ENABLE_PLATFORM_MINGW32 | ||
61 | const char *start = has_dos_drive_prefix(path) ? path+2 : path; | ||
62 | |||
63 | if (!slash) | ||
64 | slash = last_char_is(path, '\\'); | ||
65 | |||
66 | if (slash) | ||
67 | while ((*slash == '/' || *slash == '\\') && slash != start) | ||
68 | *slash-- = '\0'; | ||
69 | #else | ||
50 | if (slash) | 70 | if (slash) |
51 | while (*slash == '/' && slash != path) | 71 | while (*slash == '/' && slash != path) |
52 | *slash-- = '\0'; | 72 | *slash-- = '\0'; |
73 | #endif | ||
53 | 74 | ||
54 | return bb_get_last_path_component_nostrip(path); | 75 | return bb_get_last_path_component_nostrip(path); |
55 | } | 76 | } |