diff options
| author | Ron Yorston <rmy@pobox.com> | 2024-01-04 07:58:00 +0000 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2024-01-04 07:58:00 +0000 |
| commit | 9197a9ef026e3d57d291f05ea6f91956d152d116 (patch) | |
| tree | 57eaef12ecb831422c66d95ba0c2022bbfd7f50d /libbb | |
| parent | 306601c86fa1cc6c210b7f18d597b8c0821ab19a (diff) | |
| download | busybox-w32-9197a9ef026e3d57d291f05ea6f91956d152d116.tar.gz busybox-w32-9197a9ef026e3d57d291f05ea6f91956d152d116.tar.bz2 busybox-w32-9197a9ef026e3d57d291f05ea6f91956d152d116.zip | |
libbb: introduce last_char_is_dir_sep()
Add a convenience function to determine if the last character of
a string is a directory separator.
Adds 16-32 bytes.
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/concat_path_file.c | 4 | ||||
| -rw-r--r-- | libbb/last_char_is.c | 11 |
2 files changed, 13 insertions, 2 deletions
diff --git a/libbb/concat_path_file.c b/libbb/concat_path_file.c index 81c7481ca..3afb0e3a4 100644 --- a/libbb/concat_path_file.c +++ b/libbb/concat_path_file.c | |||
| @@ -22,8 +22,8 @@ char* FAST_FUNC concat_path_file(const char *path, const char *filename) | |||
| 22 | if (!path) | 22 | if (!path) |
| 23 | path = ""; | 23 | path = ""; |
| 24 | #if ENABLE_PLATFORM_MINGW32 | 24 | #if ENABLE_PLATFORM_MINGW32 |
| 25 | lc = last_char_is(path, '/') ?: last_char_is(path, '\\'); | 25 | lc = last_char_is_dir_sep(path); |
| 26 | while (*filename == '/' || *filename == '\\') | 26 | while (is_dir_sep(*filename)) |
| 27 | filename++; | 27 | filename++; |
| 28 | #else | 28 | #else |
| 29 | lc = last_char_is(path, '/'); | 29 | lc = last_char_is(path, '/'); |
diff --git a/libbb/last_char_is.c b/libbb/last_char_is.c index fba05f974..c2cd92174 100644 --- a/libbb/last_char_is.c +++ b/libbb/last_char_is.c | |||
| @@ -17,3 +17,14 @@ char* FAST_FUNC last_char_is(const char *s, int c) | |||
| 17 | s++; | 17 | s++; |
| 18 | return (*s == (char)c) ? (char *) s : NULL; | 18 | return (*s == (char)c) ? (char *) s : NULL; |
| 19 | } | 19 | } |
| 20 | |||
| 21 | #if ENABLE_PLATFORM_MINGW32 | ||
| 22 | char* FAST_FUNC last_char_is_dir_sep(const char *s) | ||
| 23 | { | ||
| 24 | if (!s[0]) | ||
| 25 | return NULL; | ||
| 26 | while (s[1]) | ||
| 27 | s++; | ||
| 28 | return is_dir_sep(*s)? (char *) s : NULL; | ||
| 29 | } | ||
| 30 | #endif | ||
