1 /*
2 ** mhbasename.c -- Given a path name, return a pointer to the character
3 ** -- after the last slash. If none present, return the the
4 ** -- beginning of the path.
5 **
6 ** This code is Copyright (c) 2002, by the authors of nmh. See the
7 ** COPYRIGHT file in the root directory of the nmh distribution for
8 ** complete copyright information.
9 */
10
11 #include <h/mh.h>
12
13
14 /*
15 ** Note: In contrast to POSIX basename(), we don't handle trailing
16 ** slashes special. If path has a trailing slash, we return a pointer
17 ** to a null byte (i.e. to an empty string). Also different: We don't
18 ** modify the original string neither do we return a pointer to static
19 ** memory.
20 */
21 char *
mhbasename(char * path)22 mhbasename(char *path)
23 {
24 char *cp;
25
26 if (!path) {
27 return NULL;
28 }
29 cp = strrchr(path, '/');
30 return (!cp) ? path : ++cp;
31
32 }
33