libdl: first execute all destructors, then munmap library
[uclibc-ng.git] / libc / string / dirname.c
blobc7f4dec1f5dc7d96203a989074382057f0700fa8
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 #define __need_NULL
9 #include <stddef.h>
10 #include <libgen.h>
12 char *dirname(char *path)
14 static const char null_or_empty_or_noslash[] = ".";
15 register char *s;
16 register char *last;
17 char *first;
19 last = s = path;
21 if (s != NULL) {
23 LOOP:
24 while (*s && (*s != '/')) ++s;
25 first = s;
26 while (*s == '/') ++s;
27 if (*s) {
28 last = first;
29 goto LOOP;
32 if (last == path) {
33 if (*last != '/') {
34 goto DOT;
36 if ((*++last == '/') && (last[1] == 0)) {
37 ++last;
40 *last = 0;
41 return path;
43 DOT:
44 return (char *) null_or_empty_or_noslash;