path.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * path.c - path handling functions
  4. *
  5. * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. * Copyright © 2008 Guillem Jover <guillem@debian.org>
  7. *
  8. * This is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2,
  11. * or (at your option) any later version.
  12. *
  13. * This is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with dpkg; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <config.h>
  23. #include <string.h>
  24. #include <dpkg-priv.h>
  25. size_t
  26. rtrim_slash_slashdot(char *path)
  27. {
  28. char *end;
  29. if (!path || !*path)
  30. return 0;
  31. for (end = path + strlen(path) - 1; end - path >= 1; end--) {
  32. if (*end == '/' || (*(end - 1) == '/' && *end == '.'))
  33. *end = '\0';
  34. else
  35. break;
  36. }
  37. return end - path + 1;
  38. }
  39. const char *
  40. skip_slash_dotslash(const char *path)
  41. {
  42. while (path[0] == '/' || (path[0] == '.' && path[1] == '/'))
  43. path++;
  44. return path;
  45. }