7 extern int _p9dir(struct stat*, struct stat*, char*, Dir*, char**, char*);
11 mygetdents(int fd, struct dirent *buf, int n)
16 /* This doesn't match the man page, but it works in Debian with a 2.2 kernel */
17 off = p9seek(fd, 0, 1);
18 nn = getdirentries(fd, (void*)buf, n, &off);
21 #elif defined(__APPLE__)
23 mygetdents(int fd, struct dirent *buf, int n)
26 return getdirentries(fd, (void*)buf, n, &off);
28 #elif defined(__FreeBSD__) || defined(__DragonFly__)
30 mygetdents(int fd, struct dirent *buf, int n)
33 return getdirentries(fd, (void*)buf, n, &off);
35 #elif defined(__sun__) || defined(__NetBSD__) || defined(__OpenBSD__)
37 mygetdents(int fd, struct dirent *buf, int n)
39 return getdents(fd, (void*)buf, n);
41 #elif defined(__AIX__)
43 mygetdents(int fd, struct dirent *buf, int n)
45 return getdirent(fd, (void*)buf, n);
49 #if defined(__DragonFly__)
50 static inline int d_reclen(struct dirent *de) { return _DIRENT_DIRSIZ(de); }
52 static inline int d_reclen(struct dirent *de) { return de->d_reclen; }
56 countde(char *p, int n)
65 de = (struct dirent*)p;
66 if(d_reclen(de) <= 4+2+2+1 || p+d_reclen(de) > e)
68 if(de->d_name[0]=='.' && de->d_name[1]==0)
70 else if(de->d_name[0]=='.' && de->d_name[1]=='.' && de->d_name[2]==0)
79 dirpackage(int fd, char *buf, int n, Dir **dp)
92 if((oldwd = open(".", O_RDONLY)) < 0)
101 de = (struct dirent*)p;
102 memset(&lst, 0, sizeof lst);
103 if(de->d_name[0] == 0)
105 else if(lstat(de->d_name, &lst) < 0)
109 if(S_ISLNK(lst.st_mode))
110 stat(de->d_name, &st);
111 nstr += _p9dir(&lst, &st, de->d_name, nil, nil, nil);
116 d = malloc(sizeof(Dir)*n+nstr);
128 de = (struct dirent*)p;
129 if(de->d_name[0] != 0 && lstat(de->d_name, &lst) >= 0){
131 if((lst.st_mode&S_IFMT) == S_IFLNK)
132 stat(de->d_name, &st);
133 _p9dir(&lst, &st, de->d_name, &d[m++], &str, estr);
145 dirread(int fd, Dir **dp)
153 if(fstat(fd, &st) < 0)
156 if(st.st_blksize < 8192)
157 st.st_blksize = 8192;
159 buf = malloc(st.st_blksize);
163 n = mygetdents(fd, (void*)buf, st.st_blksize);
168 n = dirpackage(fd, buf, n, dp);
175 dirreadall(int fd, Dir **d)
181 if(fstat(fd, &st) < 0)
184 if(st.st_blksize < 8192)
185 st.st_blksize = 8192;
190 nbuf = realloc(buf, ts+st.st_blksize);
196 n = mygetdents(fd, (void*)(buf+ts), st.st_blksize);
202 ts = dirpackage(fd, (char*)buf, ts, d);