diff options
author | Ron Yorston <rmy@pobox.com> | 2021-10-13 16:22:21 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2021-10-13 16:44:45 +0100 |
commit | 4daf57b4fdc80422d6448c0a7914699fdedb95b8 (patch) | |
tree | 72930a54811bcebacd06bac0d67bcec6b1da677a /libbb/get_last_path_component.c | |
parent | 0ecf1aea459571b48dc68ddc2b7b9265740fa960 (diff) | |
download | busybox-w32-4daf57b4fdc80422d6448c0a7914699fdedb95b8.tar.gz busybox-w32-4daf57b4fdc80422d6448c0a7914699fdedb95b8.tar.bz2 busybox-w32-4daf57b4fdc80422d6448c0a7914699fdedb95b8.zip |
realpath: improved support for Windows paths
Upstream commit 94eb1c4dc (libbb: better coreutils compatibility
for realpath) made some changes to xmalloc_realpath_coreutils().
This now needs to be updated to handle Windows paths.
- Expose the macro is_unc_path() and part of the recent change to
bb_get_last_path_component_nostrip() as a separate funtion,
get_last_slash();
- Convert a couple of errors relating to network filesystems to
ENOENT;
- Adjust xmalloc_realpath_coreutils() to handle Windows directory
separators, relative paths and UNC paths.
Diffstat (limited to 'libbb/get_last_path_component.c')
-rw-r--r-- | libbb/get_last_path_component.c | 23 |
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 | ||
27 | char *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; |