smbpath.c 805 B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include "headers.h"
  10. void
  11. smbpathsplit(char *path, char **dirp, char **namep)
  12. {
  13. char *dir;
  14. char *p = strrchr(path, '/');
  15. if (p == nil) {
  16. *dirp = smbestrdup("/");
  17. *namep = smbestrdup(path);
  18. return;
  19. }
  20. if (p == path)
  21. dir = smbestrdup("/");
  22. else {
  23. dir = smbemalloc(p - path + 1);
  24. memcpy(dir, path, p - path);
  25. dir[p - path] = 0;
  26. }
  27. *dirp = dir;
  28. *namep = smbestrdup(p + 1);
  29. }