blob: c950faeb35d26a8d5b40a44f57d3d70945265438 [file] [log] [blame]
Eric Andersenaad1a882001-03-16 22:47:14 +00001/* vi: set sw=4 ts=4: */
2/*
Manuel Novoa III cad53642003-03-19 09:13:01 +00003 * bb_get_last_path_component implementation for busybox
Eric Andersenaad1a882001-03-16 22:47:14 +00004 *
Manuel Novoa III cad53642003-03-19 09:13:01 +00005 * Copyright (C) 2001 Manuel Novoa III <mjn3@codepoet.org>
Eric Andersenaad1a882001-03-16 22:47:14 +00006 *
Rob Landley35709152006-03-26 21:49:42 +00007 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Eric Andersenaad1a882001-03-16 22:47:14 +00008 */
9
Manuel Novoa III cad53642003-03-19 09:13:01 +000010char *bb_get_last_path_component(char *path)
Eric Andersenaad1a882001-03-16 22:47:14 +000011{
Manuel Novoa III 3280f9a2001-12-05 04:35:32 +000012 char *first = path;
13 char *last;
Eric Andersen32574a42001-06-15 20:10:39 +000014
Manuel Novoa III 3280f9a2001-12-05 04:35:32 +000015 last = path - 1;
16
17 while (*path) {
18 if ((*path != '/') && (path > ++last)) {
19 last = first = path;
20 }
21 ++path;
Eric Andersenaad1a882001-03-16 22:47:14 +000022 }
23
Manuel Novoa III 3280f9a2001-12-05 04:35:32 +000024 if (*first == '/') {
25 last = first;
Eric Andersen32574a42001-06-15 20:10:39 +000026 }
Manuel Novoa III 3280f9a2001-12-05 04:35:32 +000027 last[1] = 0;
Eric Andersen32574a42001-06-15 20:10:39 +000028
Manuel Novoa III 3280f9a2001-12-05 04:35:32 +000029 return first;
Eric Andersenaad1a882001-03-16 22:47:14 +000030}