summaryrefslogtreecommitdiff
path: root/sysutils/9base/patches/patch-av
blob: 73820465d7f5d3e84c0b4ab67de234670c469e48 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
$NetBSD: patch-av,v 1.1 2006/06/21 19:34:45 joerg Exp $

--- lib9/dirread.c.orig	2006-06-21 17:11:56.000000000 +0000
+++ lib9/dirread.c
@@ -18,7 +18,7 @@ mygetdents(int fd, struct dirent *buf, i
 	nn = getdirentries(fd, (void*)buf, n, &off);
 	return nn;
 }
-#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
+#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
 static int
 mygetdents(int fd, struct dirent *buf, int n)
 {
@@ -44,14 +44,22 @@ countde(char *p, int n)
 	m = 0;
 	while(p < e){
 		de = (struct dirent*)p;
+#if defined(__DragonFly__)
+		if (p + _DIRENT_DIRSIZ(de) > e)
+#else
 		if(de->d_reclen <= 4+2+2+1 || p+de->d_reclen > e)
+#endif
 			break;
 		if(de->d_name[0]=='.' && de->d_name[1]==0)
 			de->d_name[0] = 0;
 		else if(de->d_name[0]=='.' && de->d_name[1]=='.' && de->d_name[2]==0)
 			de->d_name[0] = 0;
 		m++;
+#if defined(__DragonFly__)
+		p += _DIRENT_DIRSIZ(de);
+#else
 		p += de->d_reclen;
+#endif
 	}
 	return m;
 }
@@ -91,7 +99,11 @@ dirpackage(int fd, char *buf, int n, Dir
 				stat(de->d_name, &st);
 			nstr += _p9dir(&lst, &st, de->d_name, nil, nil, nil);
 		}
+#if defined(__DragonFly__)
+		p += _DIRENT_DIRSIZ(de);
+#else
 		p += de->d_reclen;
+#endif
 	}
 
 	d = malloc(sizeof(Dir)*n+nstr);
@@ -113,7 +125,11 @@ dirpackage(int fd, char *buf, int n, Dir
 				stat(de->d_name, &st);
 			_p9dir(&lst, &st, de->d_name, &d[m++], &str, estr);
 		}
+#if defined(__DragonFly__)
+		p += _DIRENT_DIRSIZ(de);
+#else
 		p += de->d_reclen;
+#endif
 	}
 
 	fchdir(oldwd);