Last change
on this file since 3872 was 3232, checked in by Bruno Cornec, 11 years ago |
- Update mindi-busybox to 1.21.1
|
File size:
1004 bytes
|
Rev | Line | |
---|
[821] | 1 | /* 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 | *
|
---|
[2725] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
---|
[821] | 8 | */
|
---|
[3232] | 9 | #include "libbb.h"
|
---|
[821] | 10 |
|
---|
[3232] | 11 | const char* FAST_FUNC bb_basename(const char *name)
|
---|
| 12 | {
|
---|
| 13 | const char *cp = strrchr(name, '/');
|
---|
| 14 | if (cp)
|
---|
| 15 | return cp + 1;
|
---|
| 16 | return name;
|
---|
| 17 | }
|
---|
| 18 |
|
---|
[2725] | 19 | /*
|
---|
| 20 | * "/" -> "/"
|
---|
| 21 | * "abc" -> "abc"
|
---|
| 22 | * "abc/def" -> "def"
|
---|
| 23 | * "abc/def/" -> ""
|
---|
| 24 | */
|
---|
| 25 | char* FAST_FUNC bb_get_last_path_component_nostrip(const char *path)
|
---|
[821] | 26 | {
|
---|
[2725] | 27 | char *slash = strrchr(path, '/');
|
---|
[821] | 28 |
|
---|
[2725] | 29 | if (!slash || (slash == path && !slash[1]))
|
---|
| 30 | return (char*)path;
|
---|
[821] | 31 |
|
---|
[2725] | 32 | return slash + 1;
|
---|
| 33 | }
|
---|
[821] | 34 |
|
---|
[2725] | 35 | /*
|
---|
| 36 | * "/" -> "/"
|
---|
| 37 | * "abc" -> "abc"
|
---|
| 38 | * "abc/def" -> "def"
|
---|
| 39 | * "abc/def/" -> "def" !!
|
---|
| 40 | */
|
---|
| 41 | char* FAST_FUNC bb_get_last_path_component_strip(char *path)
|
---|
| 42 | {
|
---|
| 43 | char *slash = last_char_is(path, '/');
|
---|
[821] | 44 |
|
---|
[2725] | 45 | if (slash)
|
---|
| 46 | while (*slash == '/' && slash != path)
|
---|
| 47 | *slash-- = '\0';
|
---|
| 48 |
|
---|
| 49 | return bb_get_last_path_component_nostrip(path);
|
---|
[821] | 50 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.