coverity appeasement
[minix.git] / commands / dirname / dirname.c
blob32d77c8c59799461711f13d81c53c5a668ea0402
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)
7 * $Log$
8 * Revision 1.1 2005/04/21 14:55:21 beng
9 * Initial revision
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
15 * Initial revision
19 #include <string.h>
20 #include <stdio.h>
22 int main(int argc, char **argv)
24 char *p;
25 char *path;
27 if (argc != 2) {
28 fprintf(stderr, "Usage: %s path\n", argv[0]);
29 return(1);
31 path = argv[1];
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 */
36 if (p == path) {
37 printf(path[0] == '/' ? "/\n" : ".\n");
38 } else {
39 printf("%.*s\n", (int) (p - path), path);
41 return(0);