From ab879a41ab674129ef1593cda181cc8b64d0dadf Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 13 Nov 2015 08:51:45 +0000 Subject: libbb: additional support for backslashes in paths --- libbb/get_last_path_component.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'libbb') 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) { char *slash = strrchr(path, '/'); +#if ENABLE_PLATFORM_MINGW32 + const char *start = has_dos_drive_prefix(path) ? path+2 : path; + + if (!slash) + slash = strrchr(path, '\\'); + + if (!slash || (slash == start && !slash[1])) + return (char*)path; +#else if (!slash || (slash == path && !slash[1])) return (char*)path; +#endif return slash + 1; } @@ -47,9 +57,20 @@ char* FAST_FUNC bb_get_last_path_component_strip(char *path) { char *slash = last_char_is(path, '/'); +#if ENABLE_PLATFORM_MINGW32 + const char *start = has_dos_drive_prefix(path) ? path+2 : path; + + if (!slash) + slash = last_char_is(path, '\\'); + + if (slash) + while ((*slash == '/' || *slash == '\\') && slash != start) + *slash-- = '\0'; +#else if (slash) while (*slash == '/' && slash != path) *slash-- = '\0'; +#endif return bb_get_last_path_component_nostrip(path); } -- cgit v1.2.3-55-g6feb