compiler/clib: Removed unused arosc_init.h file.
[AROS.git] / compiler / clib / dirname.c
blobce439460668e69f3bf59a8ca808e5ef3f0b4ffc0
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 /*****************************************************************************
15 NAME */
16 #include <libgen.h>
18 char *dirname(
20 /* SYNOPSIS */
21 char *filename)
23 /* FUNCTION
24 Returns the string up to the latest '/'.
26 INPUTS
27 filename - Path which should be split
29 RESULT
30 Directory part of the path.
32 NOTES
34 EXAMPLE
36 BUGS
38 SEE ALSO
39 basename()
41 INTERNALS
43 ******************************************************************************/
45 char *uname;
46 char *pos;
48 if (!filename || *filename == '\0')
50 D(bug("dirname()=.\n"));
51 return ".";
54 uname = (char *)__path_a2u(filename);
56 pos = uname;
58 if (pos[0] == '/' && pos[1] == '\0')
60 D(bug("dirname(/)=/\n"));
61 return uname;
64 D(bug("dirname(%s)=", filename));
66 pos = uname + strlen(uname);
67 while (pos[-1] == '/')
69 --pos;
70 pos[0] = '\0';
72 while (--pos > uname)
74 if (pos[0] == '/')
76 pos[0] = '\0';
77 break;
81 if (pos == uname)
82 uname = ".";
84 D(bug("%s\n", uname));
85 return uname;