add a missing section header table index conversion
[tangerine.git] / compiler / clib / basename.c
blob879e926807d3974b60396c86d5bbdb8fdf88ee27
1 /*
2 Copyright © 2004, The AROS Development Team. All rights reserved.
3 $Id$
5 POSIX function basename().
6 */
8 #include "__upath.h"
10 #define DEBUG 1
11 #include <aros/debug.h>
13 char *basename(char *filename)
15 char *uname;
16 char *pos;
18 if (!filename || *filename == '\0')
20 D(bug("basename()=.\n"));
21 return ".";
24 uname = (char *)__path_a2u(filename);
26 pos = uname;
28 if (pos[0] == '/' && pos[1] == '\0')
30 D(bug("basename(/)=/\n"));
31 return uname;
34 D(bug("basename(%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 uname = ++pos;
47 break;
51 D(bug("%s\n", uname));
52 return uname;