Annotation of /tags/mkinitrd-6_1_11/busybox/libbb/get_last_path_component.c
Parent Directory
|
Revision Log
Revision 928 -
(hide annotations)
(download)
Wed Oct 28 13:31:19 2009 UTC (14 years, 7 months ago) by niro
File MIME type: text/plain
File size: 877 byte(s)
Wed Oct 28 13:31:19 2009 UTC (14 years, 7 months ago) by niro
File MIME type: text/plain
File size: 877 byte(s)
tagged 'mkinitrd-6_1_11'
1 | niro | 532 | /* vi: set sw=4 ts=4: */ |
2 | /* | ||
3 | * bb_get_last_path_component implementation for busybox | ||
4 | * | ||
5 | * Copyright (C) 2001 Manuel Novoa III <mjn3@codepoet.org> | ||
6 | * | ||
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
8 | */ | ||
9 | |||
10 | #include "libbb.h" | ||
11 | niro | 816 | /* |
12 | * "/" -> "/" | ||
13 | * "abc" -> "abc" | ||
14 | * "abc/def" -> "def" | ||
15 | * "abc/def/" -> "" | ||
16 | */ | ||
17 | char* FAST_FUNC bb_get_last_path_component_nostrip(const char *path) | ||
18 | niro | 532 | { |
19 | niro | 816 | char *slash = strrchr(path, '/'); |
20 | niro | 532 | |
21 | niro | 816 | if (!slash || (slash == path && !slash[1])) |
22 | return (char*)path; | ||
23 | niro | 532 | |
24 | niro | 816 | return slash + 1; |
25 | } | ||
26 | niro | 532 | |
27 | niro | 816 | /* |
28 | * "/" -> "/" | ||
29 | * "abc" -> "abc" | ||
30 | * "abc/def" -> "def" | ||
31 | * "abc/def/" -> "def" !! | ||
32 | */ | ||
33 | char* FAST_FUNC bb_get_last_path_component_strip(char *path) | ||
34 | { | ||
35 | char *slash = last_char_is(path, '/'); | ||
36 | niro | 532 | |
37 | niro | 816 | if (slash) |
38 | while (*slash == '/' && slash != path) | ||
39 | *slash-- = '\0'; | ||
40 | |||
41 | return bb_get_last_path_component_nostrip(path); | ||
42 | niro | 532 | } |