get_last_path_component.c 536 B

1234567891011121314151617181920212223242526272829303132
  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. #include "libbb.h"
  10. char *bb_get_last_path_component(char *path)
  11. {
  12. char *first = path;
  13. char *last;
  14. last = path - 1;
  15. while (*path) {
  16. if ((*path != '/') && (path > ++last)) {
  17. last = first = path;
  18. }
  19. ++path;
  20. }
  21. if (*first == '/') {
  22. last = first;
  23. }
  24. last[1] = '\0';
  25. return first;
  26. }