Don't try to setup and use X11 shared memory if
[tangerine.git] / compiler / clib / basename.c
blobf2208352e3c6d86d28305032ed340b9e62e135c6
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 /*****************************************************************************
15 NAME */
16 #include <libgen.h>
18 char *basename(
20 /* SYNOPSIS */
21 char *filename)
23 /* FUNCTION
24 Returns the part after the latest '/' of a path.
25 Trailing '/' are not counted as part of the path.
27 INPUTS
28 filename - Path which should be split.
30 RESULT
31 Rightmost part of the path.
33 NOTES
35 EXAMPLE
37 BUGS
39 SEE ALSO
40 dirname()
42 INTERNALS
44 ******************************************************************************/
46 char *uname;
47 char *pos;
49 if (!filename || *filename == '\0')
51 D(bug("basename()=.\n"));
52 return ".";
55 uname = (char *)__path_a2u(filename);
57 pos = uname;
59 if (pos[0] == '/' && pos[1] == '\0')
61 D(bug("basename(/)=/\n"));
62 return uname;
65 D(bug("basename(%s)=", filename));
67 pos = uname + strlen(uname);
68 while (pos[-1] == '/')
70 --pos;
71 pos[0] = '\0';
73 while (--pos > uname)
75 if (pos[0] == '/')
77 uname = ++pos;
78 break;
82 D(bug("%s\n", uname));
83 return uname;