purge remaining gpl code from clib, and make clib build again
[tangerine.git] / compiler / clib / dirname.c
bloba78c3adf3aecf55093800b1c507727bbfe9cbc3b
1 /*
2 Copyright © 2004, The AROS Development Team. All rights reserved.
3 $Id$
5 POSIX function dirname().
6 */
8 #include "__upath.h"
10 #define DEBUG 0
11 #include <aros/debug.h>
13 char *dirname(char *filename)
15 char *uname;
16 char *pos;
18 if (!filename || *filename == '\0')
20 D(bug("dirname()=.\n"));
21 return ".";
24 uname = (char *)__path_a2u(filename);
26 pos = uname;
28 if (pos[0] == '/' && pos[1] == '\0')
30 D(bug("dirname(/)=/\n"));
31 return uname;
34 D(bug("dirname(%s)=", filename));
36 pos = uname + strlen(uname);
37 while (pos[-1] == '/')
39 --pos;
40 pos[0] = '\0';
42 while (--pos > uname)
44 if (pos[0] == '/')
46 pos[0] = '\0';
47 break;
51 if (pos == uname)
52 uname = ".";
54 D(bug("%s\n", uname));
55 return uname;