Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | ||||
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 3 | * bb_get_last_path_component implementation for busybox |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 4 | * |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 5 | * Copyright (C) 2001 Manuel Novoa III <mjn3@codepoet.org> |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 6 | * |
Rob Landley | 3570915 | 2006-03-26 21:49:42 +0000 | [diff] [blame] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 8 | */ |
9 | |||||
Bernhard Reutner-Fischer | 421d9e5 | 2006-04-03 16:39:31 +0000 | [diff] [blame] | 10 | #include "libbb.h" |
11 | |||||
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 12 | char *bb_get_last_path_component(char *path) |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 13 | { |
Manuel Novoa III | 3280f9a | 2001-12-05 04:35:32 +0000 | [diff] [blame] | 14 | char *first = path; |
15 | char *last; | ||||
Eric Andersen | 32574a4 | 2001-06-15 20:10:39 +0000 | [diff] [blame] | 16 | |
Manuel Novoa III | 3280f9a | 2001-12-05 04:35:32 +0000 | [diff] [blame] | 17 | last = path - 1; |
18 | |||||
19 | while (*path) { | ||||
20 | if ((*path != '/') && (path > ++last)) { | ||||
21 | last = first = path; | ||||
22 | } | ||||
23 | ++path; | ||||
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 24 | } |
25 | |||||
Manuel Novoa III | 3280f9a | 2001-12-05 04:35:32 +0000 | [diff] [blame] | 26 | if (*first == '/') { |
27 | last = first; | ||||
Eric Andersen | 32574a4 | 2001-06-15 20:10:39 +0000 | [diff] [blame] | 28 | } |
Manuel Novoa III | 3280f9a | 2001-12-05 04:35:32 +0000 | [diff] [blame] | 29 | last[1] = 0; |
Eric Andersen | 32574a4 | 2001-06-15 20:10:39 +0000 | [diff] [blame] | 30 | |
Manuel Novoa III | 3280f9a | 2001-12-05 04:35:32 +0000 | [diff] [blame] | 31 | return first; |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 32 | } |