]> git.karo-electronics.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>
Tue, 23 Oct 2012 02:50:31 +0000 (13:50 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Tue, 23 Oct 2012 03:11:57 +0000 (14:11 +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_ */