home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume24 / mkid2 / part01 / basename.c next >
C/C++ Source or Header  |  1991-10-09  |  433b  |  32 lines

  1. /* Copyright (c) 1986, Greg McGary */
  2. static char sccsid[] = "@(#)basename.c    1.1 86/10/09";
  3.  
  4. #include    <string.h>
  5.  
  6. char *basename();
  7. char *dirname();
  8.  
  9. char *
  10. basename(path)
  11.     char        *path;
  12. {
  13.     char        *base;
  14.  
  15.     if ((base = strrchr(path, '/')) == 0)
  16.         return path;
  17.     else
  18.         return ++base;
  19. }
  20.  
  21. char *
  22. dirname(path)
  23.     char        *path;
  24. {
  25.     char        *base;
  26.  
  27.     if ((base = strrchr(path, '/')) == 0)
  28.         return ".";
  29.     else
  30.         return strnsav(path, base - path);
  31. }
  32.