diff options
Diffstat (limited to 'libbb/get_last_path_component.c')
-rw-r--r-- | libbb/get_last_path_component.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/libbb/get_last_path_component.c b/libbb/get_last_path_component.c index 04fdf2a3e..15eb85ca8 100644 --- a/libbb/get_last_path_component.c +++ b/libbb/get_last_path_component.c | |||
@@ -13,6 +13,11 @@ const char* FAST_FUNC bb_basename(const char *name) | |||
13 | const char *cp = strrchr(name, '/'); | 13 | const char *cp = strrchr(name, '/'); |
14 | if (cp) | 14 | if (cp) |
15 | return cp + 1; | 15 | return cp + 1; |
16 | #if ENABLE_PLATFORM_MINGW32 | ||
17 | cp = strrchr(name, '\\'); | ||
18 | if (cp) | ||
19 | return cp + 1; | ||
20 | #endif | ||
16 | return name; | 21 | return name; |
17 | } | 22 | } |
18 | 23 | ||
@@ -26,8 +31,18 @@ char* FAST_FUNC bb_get_last_path_component_nostrip(const char *path) | |||
26 | { | 31 | { |
27 | char *slash = strrchr(path, '/'); | 32 | char *slash = strrchr(path, '/'); |
28 | 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 | ||
29 | if (!slash || (slash == path && !slash[1])) | 43 | if (!slash || (slash == path && !slash[1])) |
30 | return (char*)path; | 44 | return (char*)path; |
45 | #endif | ||
31 | 46 | ||
32 | return slash + 1; | 47 | return slash + 1; |
33 | } | 48 | } |
@@ -42,9 +57,20 @@ char* FAST_FUNC bb_get_last_path_component_strip(char *path) | |||
42 | { | 57 | { |
43 | char *slash = last_char_is(path, '/'); | 58 | char *slash = last_char_is(path, '/'); |
44 | 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 | ||
45 | if (slash) | 70 | if (slash) |
46 | while (*slash == '/' && slash != path) | 71 | while (*slash == '/' && slash != path) |
47 | *slash-- = '\0'; | 72 | *slash-- = '\0'; |
73 | #endif | ||
48 | 74 | ||
49 | return bb_get_last_path_component_nostrip(path); | 75 | return bb_get_last_path_component_nostrip(path); |
50 | } | 76 | } |