X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Fmhbasename.c;fp=sbr%2Fmhbasename.c;h=038e506d2365ebf68f759a80019573d8ca47f2d3;hp=0000000000000000000000000000000000000000;hb=240013872c392fe644bd4f79382d9f5314b4ea60;hpb=c20b4fa14515c7ab388ce35411d89a7a92300711 diff --git a/sbr/mhbasename.c b/sbr/mhbasename.c new file mode 100644 index 0000000..038e506 --- /dev/null +++ b/sbr/mhbasename.c @@ -0,0 +1,32 @@ +/* +** mhbasename.c -- Given a path name, return a pointer to the character +** -- after the last slash. If none present, return the the +** -- beginning of the path. +** +** This code is Copyright (c) 2002, by the authors of nmh. See the +** COPYRIGHT file in the root directory of the nmh distribution for +** complete copyright information. +*/ + +#include + + +/* +** Note: In contrast to POSIX basename(), we don't handle trailing +** slashes special. If path has a trailing slash, we return a pointer +** to a null byte (i.e. to an empty string). Also different: We don't +** modify the original string neither do we return a pointer to static +** memory. +*/ +char * +mhbasename(char *path) +{ + char *cp; + + if (!path) { + return NULL; + } + cp = strrchr(path, '/'); + return (!cp) ? path : ++cp; + +}