tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / compiler / posixc / dirname.c
blobbf245264ffb8b4cb833926fd4de040d378d294cd
1 /*
2 Copyright © 2004, The AROS Development Team. All rights reserved.
3 $Id$
5 POSIX.1-2008 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;