path.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 <compat.h>
  24. #include <string.h>
  25. #include <dpkg-priv.h>
  26. size_t
  27. rtrim_slash_slashdot(char *path)
  28. {
  29. char *end;
  30. if (!path || !*path)
  31. return 0;
  32. for (end = path + strlen(path) - 1; end - path >= 1; end--) {
  33. if (*end == '/' || (*(end - 1) == '/' && *end == '.'))
  34. *end = '\0';
  35. else
  36. break;
  37. }
  38. return end - path + 1;
  39. }
  40. const char *
  41. skip_slash_dotslash(const char *path)
  42. {
  43. while (path[0] == '/' || (path[0] == '.' && path[1] == '/'))
  44. path++;
  45. return path;
  46. }