source: trunk/minix/commands/simple/dirname.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 982 bytes
RevLine 
[9]1/* dirname - extract the directory name from a path Author: Peter Holzer */
2
3/* Dirname -- extract directory part from a path name
4 *
5 * Peter Holzer (hp@vmars.tuwien.ac.at)
6 *
7 * $Log: dirname.c,v $
8 * Revision 1.1.1.1 2005/04/21 14:55:21 beng
9 * Initial import of pre-3.0.1
10 *
11 * Revision 1.1.1.1 2005/04/20 13:33:30 beng
12 * Initial import of minix 2.0.4
13 *
14 * Revision 1.1 1994/02/12 16:15:02 hjp
15 * Initial revision
16 *
17 */
18
19#include <string.h>
20#include <stdio.h>
21
22int main(int argc, char **argv)
23{
24 char *p;
25 char *path;
26
27 if (argc != 2) {
28 fprintf(stderr, "Usage: %s path\n", argv[0]);
29 return(1);
30 }
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);
40 }
41 return(0);
42}
Note: See TracBrowser for help on using the repository browser.