Skip to content

Commit

Permalink
string: introduce helper to get base file name from given path
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Jason Baron <[email protected]>
Cc: YAMANE Toshiaki <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Steven Rostedt <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
andy-shev authored and torvalds committed Dec 18, 2012
1 parent 0edd807 commit b18888a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/linux/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */

0 comments on commit b18888a

Please sign in to comment.