Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. #ifndef _NO_BASENAME
  2. /* Copyright 2005 Shaun Jackman
  3.  * Permission to use, copy, modify, and distribute this software
  4.  * is freely granted, provided that this notice is preserved.
  5.  */
  6.  
  7. #include <libgen.h>
  8. #include <string.h>
  9.  
  10. char*
  11. _DEFUN (basename, (path),
  12.         char *path)
  13. {
  14.         char *p;
  15.         if( path == NULL || *path == '\0' )
  16.                 return ".";
  17.         p = path + strlen(path) - 1;
  18.         while( *p == '/' ) {
  19.                 if( p == path )
  20.                         return path;
  21.                 *p-- = '\0';
  22.         }
  23.         while( p >= path && *p != '/' )
  24.                 p--;
  25.         return p + 1;
  26. }
  27.  
  28. #endif /* !_NO_BASENAME  */
  29.