get_last_path_component.c 513 B

123456789101112131415161718192021222324252627282930
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * bb_get_last_path_component implementation for busybox
  4. *
  5. * Copyright (C) 2001 Manuel Novoa III <mjn3@codepoet.org>
  6. *
  7. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  8. */
  9. char *bb_get_last_path_component(char *path)
  10. {
  11. char *first = path;
  12. char *last;
  13. last = path - 1;
  14. while (*path) {
  15. if ((*path != '/') && (path > ++last)) {
  16. last = first = path;
  17. }
  18. ++path;
  19. }
  20. if (*first == '/') {
  21. last = first;
  22. }
  23. last[1] = 0;
  24. return first;
  25. }