1 /* 2 * Copyright (c) 1987 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 char copyright[] = 10 "@(#) Copyright (c) 1987 Regents of the University of California.\n\ 11 All rights reserved.\n"; 12 #endif /* not lint */ 13 14 #ifndef lint 15 static char sccsid[] = "@(#)dirname.c 5.5 (Berkeley) 06/01/90"; 16 #endif /* not lint */ 17 18 #include <stdio.h> 19 20 main(argc, argv) 21 int argc; 22 char **argv; 23 { 24 char *p, *rindex(); 25 26 if (argc != 2) { 27 fprintf(stderr, "usage: dirname path\n"); 28 exit(1); 29 } 30 if (p = rindex(*++argv, '/')) 31 if (p > *argv) 32 *p = '\0'; 33 else 34 *++p = '\0'; 35 else 36 *argv = "."; 37 printf("%s\n", *argv); 38 exit(0); 39 } 40