summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2004-10-02 18:13:25 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2004-10-02 18:13:25 +0000
commitc840a2fdc1e470c34810f3c8b0faa2f9c75c721c (patch)
tree689d7d44b7512e5a0fe3951f8872926d0cb4f105
parente32672338be11d94f2e8f5a16e2e1d4f83ed0a1b (diff)
Keep calling getdirentries() until we no longer fill up our buffer.
-rw-r--r--usr.bin/diff/diffdir.c36
1 files changed, 22 insertions, 14 deletions
diff --git a/usr.bin/diff/diffdir.c b/usr.bin/diff/diffdir.c
index bf2b3f01ff5..1a870701533 100644
--- a/usr.bin/diff/diffdir.c
+++ b/usr.bin/diff/diffdir.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diffdir.c,v 1.27 2004/03/16 00:40:34 millert Exp $ */
+/* $OpenBSD: diffdir.c,v 1.28 2004/10/02 18:13:24 millert Exp $ */
/*
* Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -21,7 +21,7 @@
*/
#ifndef lint
-static const char rcsid[] = "$OpenBSD: diffdir.c,v 1.27 2004/03/16 00:40:34 millert Exp $";
+static const char rcsid[] = "$OpenBSD: diffdir.c,v 1.28 2004/10/02 18:13:24 millert Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -183,18 +183,26 @@ slurpdir(char *path, char **bufp, int enoentok)
}
fstat(fd, &sb);
- bufsize = sb.st_size;
- if (bufsize < sb.st_blksize)
- bufsize = sb.st_blksize;
- buf = emalloc(bufsize);
-
- nbytes = getdirentries(fd, buf, bufsize, &base);
- if (nbytes <= 0) {
- free(buf);
- warn("%s", path);
- return (NULL);
- }
- ebuf = buf + nbytes;
+ bufsize = 0;
+ ebuf = buf = NULL;
+ do {
+ bufsize += roundup(MAX(sb.st_size, sb.st_blksize),
+ sizeof(struct dirent));
+ if (buf == NULL)
+ buf = ebuf = emalloc(bufsize);
+ else {
+ cp = erealloc(buf, bufsize);
+ ebuf = cp + (ebuf - buf);
+ buf = cp;
+ }
+ nbytes = getdirentries(fd, ebuf, bufsize, &base);
+ if (nbytes == -1) {
+ free(buf);
+ warn("%s", path);
+ return (NULL);
+ }
+ ebuf += nbytes;
+ } while (nbytes == bufsize);
close(fd);
/*