libdl: first execute all destructors, then munmap library
[uclibc-ng.git] / libc / string / __xpg_basename.c
blob2e7ade91311409ff5c288439355be111d46c348b
1 /*
2 * Copyright (C) 2002 Manuel Novoa III
3 * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
5 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
6 */
8 #include <libgen.h>
10 char *__xpg_basename(register char *path)
12 static const char null_or_empty[] = ".";
13 char *first;
14 register char *last;
16 first = (char *) null_or_empty;
18 if (path && *path) {
19 first = path;
20 last = path - 1;
22 do {
23 if ((*path != '/') && (path > ++last)) {
24 last = first = path;
26 } while (*++path);
28 if (*first == '/') {
29 last = first;
31 last[1] = 0;
34 return first;
36 #ifndef __USE_GNU
37 # undef basename
38 weak_alias(__xpg_basename,basename)
39 #endif