aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2024-01-04 07:58:00 +0000
committerRon Yorston <rmy@pobox.com>2024-01-04 07:58:00 +0000
commit9197a9ef026e3d57d291f05ea6f91956d152d116 (patch)
tree57eaef12ecb831422c66d95ba0c2022bbfd7f50d
parent306601c86fa1cc6c210b7f18d597b8c0821ab19a (diff)
downloadbusybox-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.
-rw-r--r--include/libbb.h1
-rw-r--r--libbb/concat_path_file.c4
-rw-r--r--libbb/last_char_is.c11
3 files changed, 14 insertions, 2 deletions
diff --git a/include/libbb.h b/include/libbb.h
index a469bfe03..6549c8c83 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -589,6 +589,7 @@ char *bb_get_last_path_component_nostrip(const char *path) FAST_FUNC;
589const char *bb_basename(const char *name) FAST_FUNC; 589const char *bb_basename(const char *name) FAST_FUNC;
590/* NB: can violate const-ness (similarly to strchr) */ 590/* NB: can violate const-ness (similarly to strchr) */
591char *last_char_is(const char *s, int c) FAST_FUNC; 591char *last_char_is(const char *s, int c) FAST_FUNC;
592char *last_char_is_dir_sep(const char *s) FAST_FUNC;
592const char* endofname(const char *name) FAST_FUNC; 593const char* endofname(const char *name) FAST_FUNC;
593char *is_prefixed_with(const char *string, const char *key) FAST_FUNC; 594char *is_prefixed_with(const char *string, const char *key) FAST_FUNC;
594char *is_suffixed_with(const char *string, const char *key) FAST_FUNC; 595char *is_suffixed_with(const char *string, const char *key) FAST_FUNC;
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
22char* 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