dirname.c

Go to the documentation of this file.
00001 /* dirname - extract the directory name from a path     Author: Peter Holzer */
00002 
00003 /* Dirname -- extract directory part from a path name
00004  *
00005  * Peter Holzer (hp@vmars.tuwien.ac.at)
00006  *
00007  * $Log: dirname.c,v $
00008  * Revision 1.1.1.1  2005/04/21 14:55:21  beng
00009  * Initial import of pre-3.0.1
00010  *
00011  * Revision 1.1.1.1  2005/04/20 13:33:30  beng
00012  * Initial import of minix 2.0.4
00013  *
00014  * Revision 1.1  1994/02/12  16:15:02  hjp
00015  * Initial revision
00016  *
00017  */
00018 
00019 #include <string.h>
00020 #include <stdio.h>
00021 
00022 int main(int argc, char **argv)
00023 {
00024   char *p;
00025   char *path;
00026 
00027   if (argc != 2) {
00028         fprintf(stderr, "Usage: %s path\n", argv[0]);
00029         return(1);
00030   }
00031   path = argv[1];
00032   p = path + strlen(path);
00033   while (p > path && p[-1] == '/') p--; /* trailing slashes */
00034   while (p > path && p[-1] != '/') p--; /* last component */
00035   while (p > path && p[-1] == '/') p--; /* trailing slashes */
00036   if (p == path) {
00037         printf(path[0] == '/' ? "/\n" : ".\n");
00038   } else {
00039         printf("%.*s\n", (int) (p - path), path);
00040   }
00041   return(0);
00042 }

Generated on Fri Apr 14 22:57:05 2006 for minix by  doxygen 1.4.6