]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
string: introduce helper to get base file name from given path
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Sat, 3 Nov 2012 00:42:48 +0000 (11:42 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Tue, 6 Nov 2012 04:58:38 +0000 (15:58 +1100)
There are several places in the kernel that use functionality like
basename(3) with the exception: in case of '/foo/bar/' we expect to get an
empty string.  Let's do it common helper for them.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: YAMANE Toshiaki <yamanetoshi@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/string.h

index 630125818ca8177c5a90a8600e20cfc053e9fca6..ac889c5ea11bd68a846b7c84bb788115ba9b2cec 100644 (file)
@@ -143,4 +143,15 @@ static inline bool strstarts(const char *str, const char *prefix)
 
 extern size_t memweight(const void *ptr, 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;
+}
+
 #endif /* _LINUX_STRING_H_ */