aboutsummaryrefslogtreecommitdiff
path: root/libbb/get_last_path_component.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/get_last_path_component.c')
-rw-r--r--libbb/get_last_path_component.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/libbb/get_last_path_component.c b/libbb/get_last_path_component.c
index 06033e139..254aabafd 100644
--- a/libbb/get_last_path_component.c
+++ b/libbb/get_last_path_component.c
@@ -23,6 +23,21 @@ const char* FAST_FUNC bb_basename(const char *name)
23 return name; 23 return name;
24} 24}
25 25
26#if ENABLE_PLATFORM_MINGW32
27char *get_last_slash(const char *path)
28{
29 const char *start = path + root_len(path);
30 char *slash = strrchr(start, '/');
31 char *bslash = strrchr(start, '\\');
32
33 if (slash && bslash)
34 slash = MAX(slash, bslash);
35 else if (!slash)
36 slash = bslash;
37 return slash;
38}
39#endif
40
26/* 41/*
27 * "/" -> "/" 42 * "/" -> "/"
28 * "abc" -> "abc" 43 * "abc" -> "abc"
@@ -33,13 +48,7 @@ char* FAST_FUNC bb_get_last_path_component_nostrip(const char *path)
33{ 48{
34#if ENABLE_PLATFORM_MINGW32 49#if ENABLE_PLATFORM_MINGW32
35 const char *start = path + root_len(path); 50 const char *start = path + root_len(path);
36 char *slash = strrchr(start, '/'); 51 char *slash = get_last_slash(path);
37 char *bslash = strrchr(start, '\\');
38
39 if (slash && bslash)
40 slash = MAX(slash, bslash);
41 else if (!slash)
42 slash = bslash;
43 52
44 if (!slash && has_dos_drive_prefix(path) && path[2] != '\0') 53 if (!slash && has_dos_drive_prefix(path) && path[2] != '\0')
45 return (char *)path + 2; 54 return (char *)path + 2;