summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2018-10-16 12:15:43 -0700
committerSascha Hauer <s.hauer@pengutronix.de>2018-10-18 09:02:24 +0200
commitc41dfceb951b795357a014205faebac2853f7c02 (patch)
treeca80fb7dc8912779b3143b9d163e61fb1aa9fe3f /include
parent3e06eceaf441cfbe02dc4c436dc77ac28a0e5cb9 (diff)
downloadbarebox-c41dfceb951b795357a014205faebac2853f7c02.tar.gz
barebox-c41dfceb951b795357a014205faebac2853f7c02.tar.xz
linux: string: Port kbasename()
Port kbasename() from Linux and use it to implement basename() we already have. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include')
-rw-r--r--include/linux/string.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/include/linux/string.h b/include/linux/string.h
index 3418b4fbe4..c9823dab8e 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -111,6 +111,18 @@ extern char *strim(char *);
void *memchr_inv(const void *start, int c, size_t bytes);
+/**
+ * kbasename - return the last part of a pathname.
+ *
+ * @path: path to extract the filename from.
+ */
+static inline const char *kbasename(const char *path)
+{
+ const char *tail = strrchr(path, '/');
+ return tail ? tail + 1 : path;
+}
+
+
#ifdef __cplusplus
}
#endif