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 --- include/mingw.h | 2 +- libbb/get_last_path_component.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) 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 const char * next_path_sep(const char *path); #define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':') -#define is_absolute_path(path) ((path)[0] == '/' || has_dos_drive_prefix(path)) +#define is_absolute_path(path) ((path)[0] == '/' || (path)[0] == '\\' || has_dos_drive_prefix(path)) /* * 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) { 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