smbdircache.c 631 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "headers.h"
  2. SmbDirCache *
  3. smbmkdircache(SmbTree *t, char *path)
  4. {
  5. long n;
  6. SmbDirCache *c;
  7. Dir *buf;
  8. int fd;
  9. char *fullpath = nil;
  10. smbstringprint(&fullpath, "%s%s", t->serv->path, path);
  11. //smblogprintif(1, "smbmkdircache: path %s\n", fullpath);
  12. fd = open(fullpath, OREAD);
  13. free(fullpath);
  14. if (fd < 0)
  15. return nil;
  16. n = dirreadall(fd, &buf);
  17. close(fd);
  18. if (n < 0) {
  19. free(buf);
  20. return nil;
  21. }
  22. c = smbemalloc(sizeof(SmbDirCache));
  23. c->buf = buf;
  24. c->n = n;
  25. c->i = 0;
  26. return c;
  27. }
  28. void
  29. smbdircachefree(SmbDirCache **cp)
  30. {
  31. SmbDirCache *c;
  32. c = *cp;
  33. if (c) {
  34. free(c->buf);
  35. free(c);
  36. *cp = nil;
  37. }
  38. }