Changes for kernel and Busybox
[tomato.git] / release / src / router / busybox / libbb / get_last_path_component.c
blob04fdf2a3e5700bc24184ed2fc0e9e47962988712
1 /* vi: set sw=4 ts=4: */
2 /*
3 * bb_get_last_path_component implementation for busybox
5 * Copyright (C) 2001 Manuel Novoa III <mjn3@codepoet.org>
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8 */
9 #include "libbb.h"
11 const char* FAST_FUNC bb_basename(const char *name)
13 const char *cp = strrchr(name, '/');
14 if (cp)
15 return cp + 1;
16 return name;
20 * "/" -> "/"
21 * "abc" -> "abc"
22 * "abc/def" -> "def"
23 * "abc/def/" -> ""
25 char* FAST_FUNC bb_get_last_path_component_nostrip(const char *path)
27 char *slash = strrchr(path, '/');
29 if (!slash || (slash == path && !slash[1]))
30 return (char*)path;
32 return slash + 1;
36 * "/" -> "/"
37 * "abc" -> "abc"
38 * "abc/def" -> "def"
39 * "abc/def/" -> "def" !!
41 char* FAST_FUNC bb_get_last_path_component_strip(char *path)
43 char *slash = last_char_is(path, '/');
45 if (slash)
46 while (*slash == '/' && slash != path)
47 *slash-- = '\0';
49 return bb_get_last_path_component_nostrip(path);