summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2021-05-03 13:48:48 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2021-05-03 13:55:29 +0200
commit015d5be8d66386fb9386f565b9d0e04ca78f8061 (patch)
tree108aae241706ca2d76f1e2b0c56e805609568d0a /lib
parent7a1ae4f032053ed1c2acbfc7b5cf59aa1539e61e (diff)
downloadbarebox-015d5be8d66386fb9386f565b9d0e04ca78f8061.tar.gz
barebox-015d5be8d66386fb9386f565b9d0e04ca78f8061.tar.xz
string: implement strstarts along with strends
Both can be useful when parsing file paths. They are added to different files, because only one of them is available in upstream <linux/string.h>. The other we add to <string.h>, which contains more barebox-specific string functions. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210503114901.13095-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/string.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/string.c b/lib/string.c
index dbb66fe4d2..bad186586f 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -866,6 +866,15 @@ int strtobool(const char *str, int *val)
}
EXPORT_SYMBOL(strtobool);
+bool strends(const char *str, const char *postfix)
+{
+ if (strlen(str) < strlen(postfix))
+ return false;
+
+ return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0;
+}
+EXPORT_SYMBOL(strends);
+
/**
* match_string - matches given string in an array
* @array: array of strings