smbpath.c 393 B

12345678910111213141516171819202122
  1. #include "headers.h"
  2. void
  3. smbpathsplit(char *path, char **dirp, char **namep)
  4. {
  5. char *dir;
  6. char *p = strrchr(path, '/');
  7. if (p == nil) {
  8. *dirp = smbestrdup("/");
  9. *namep = smbestrdup(path);
  10. return;
  11. }
  12. if (p == path)
  13. dir = smbestrdup("/");
  14. else {
  15. dir = smbemalloc(p - path + 1);
  16. memcpy(dir, path, p - path);
  17. dir[p - path] = 0;
  18. }
  19. *dirp = dir;
  20. *namep = smbestrdup(p + 1);
  21. }