blob: 2449d1d420405e70699072241d129e3f152058c1 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/*
2 * Copyright (C) 2002 Manuel Novoa III
3 * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
4 *
5 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
6 */
7
8#include "_string.h"
9#include <libgen.h>
10
11char *__xpg_basename(register char *path)
12{
13 static const char null_or_empty[] = ".";
14 char *first;
15 register char *last;
16
17 first = (char *) null_or_empty;
18
19 if (path && *path) {
20 first = path;
21 last = path - 1;
22
23 do {
24 if ((*path != '/') && (path > ++last)) {
25 last = first = path;
26 }
27 } while (*++path);
28
29 if (*first == '/') {
30 last = first;
31 }
32 last[1] = 0;
33 }
34
35 return first;
36}