1 /* dirname - extract the directory name from a path Author: Peter Holzer */
3 /* Dirname -- extract directory part from a path name
5 * Peter Holzer (hp@vmars.tuwien.ac.at)
8 * Revision 1.1 2005/04/21 14:55:21 beng
11 * Revision 1.1.1.1 2005/04/20 13:33:30 beng
12 * Initial import of minix 2.0.4
14 * Revision 1.1 1994/02/12 16:15:02 hjp
22 int main(int argc
, char **argv
)
28 fprintf(stderr
, "Usage: %s path\n", argv
[0]);
32 p
= path
+ strlen(path
);
33 while (p
> path
&& p
[-1] == '/') p
--; /* trailing slashes */
34 while (p
> path
&& p
[-1] != '/') p
--; /* last component */
35 while (p
> path
&& p
[-1] == '/') p
--; /* trailing slashes */
37 printf(path
[0] == '/' ? "/\n" : ".\n");
39 printf("%.*s\n", (int) (p
- path
), path
);