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 | |||||
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 10 | char *bb_get_last_path_component(char *path) |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 11 | { |
Manuel Novoa III | 3280f9a | 2001-12-05 04:35:32 +0000 | [diff] [blame] | 12 | char *first = path; |
13 | char *last; | ||||
Eric Andersen | 32574a4 | 2001-06-15 20:10:39 +0000 | [diff] [blame] | 14 | |
Manuel Novoa III | 3280f9a | 2001-12-05 04:35:32 +0000 | [diff] [blame] | 15 | last = path - 1; |
16 | |||||
17 | while (*path) { | ||||
18 | if ((*path != '/') && (path > ++last)) { | ||||
19 | last = first = path; | ||||
20 | } | ||||
21 | ++path; | ||||
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 22 | } |
23 | |||||
Manuel Novoa III | 3280f9a | 2001-12-05 04:35:32 +0000 | [diff] [blame] | 24 | if (*first == '/') { |
25 | last = first; | ||||
Eric Andersen | 32574a4 | 2001-06-15 20:10:39 +0000 | [diff] [blame] | 26 | } |
Manuel Novoa III | 3280f9a | 2001-12-05 04:35:32 +0000 | [diff] [blame] | 27 | last[1] = 0; |
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 | return first; |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 30 | } |