basename.c 675 B

1234567891011121314151617181920212223242526272829303132
  1. /* basename.c -- return the last element in a path */
  2. #if HAVE_CONFIG_H
  3. # include <config.h>
  4. #endif
  5. #include <backupfile.h>
  6. #ifndef FILESYSTEM_PREFIX_LEN
  7. #define FILESYSTEM_PREFIX_LEN(f) 0
  8. #endif
  9. #ifndef ISSLASH
  10. #define ISSLASH(c) ((c) == '/')
  11. #endif
  12. /* In general, we can't use the builtin `basename' function if available,
  13. since it has different meanings in different environments.
  14. In some environments the builtin `basename' modifies its argument. */
  15. char *
  16. base_name (name)
  17. char const *name;
  18. {
  19. char const *base = name += FILESYSTEM_PREFIX_LEN (name);
  20. for (; *name; name++)
  21. if (ISSLASH (*name))
  22. base = name + 1;
  23. return (char *) base;
  24. }