summaryrefslogtreecommitdiff
path: root/sys/src/cmd/aquarela/smbdircache.c
blob: d7ee3c412da34f9c043efdfd8f46d593822fa1bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "headers.h"

SmbDirCache *
smbmkdircache(SmbTree *t, char *path)
{
	long n;
	SmbDirCache *c;
	Dir *buf;
	int fd;
	char *fullpath = nil;

	smbstringprint(&fullpath, "%s%s", t->serv->path, path);
//smblogprintif(1, "smbmkdircache: path %s\n", fullpath);
	fd = open(fullpath, OREAD);
	free(fullpath);

	if (fd < 0)
		return nil;
	n = dirreadall(fd, &buf);
	close(fd);
	if (n < 0) {
		free(buf);
		return nil;
	}
	c = smbemalloc(sizeof(SmbDirCache));
	c->buf = buf;
	c->n = n;
	c->i = 0;
	return c;
}

void
smbdircachefree(SmbDirCache **cp)
{
	SmbDirCache *c;
	c = *cp;
	if (c) {
		free(c->buf);
		free(c);
		*cp = nil;
	}
}