about summary refs log tree commit diff
path: root/holes.c
diff options
context:
space:
mode:
Diffstat (limited to 'holes.c')
-rw-r--r--holes.c37
1 files changed, 27 insertions, 10 deletions
diff --git a/holes.c b/holes.c
index 41fc50c..6bff701 100644
--- a/holes.c
+++ b/holes.c
@@ -16,20 +16,37 @@ holes(FILE *input, char *filename)
 {
 	off_t offset = 0;
 	off_t run = 0;	
-	int ch;
+	static char buf[16384];
 
-	while ((ch = getc_unlocked(input)) != EOF) {
-		if (ch == byte) {
-			run++;
+	int len;
+	int i;
+	char *d;
+
+	while ((len = fread(buf, 1, sizeof buf, input)) >= 1) {
+		if (run == 0) {
+			d = memchr(buf, byte, len);
+			if (!d) {
+				offset += len;
+				continue;
+			}
+			i = d - buf;
+			offset += i;
 		} else {
-			if (run >= minlen) {
-				if (filename)
-					printf("%s: ", filename);
-				printf("%08lx %ld\n", offset - run, run);
+			i = 0;
+		}
+		for (; i < len; i++) {
+			if (buf[i] == byte) {
+				run++;
+			} else {
+				if (run >= minlen) {
+					if (filename)
+						printf("%s: ", filename);
+					printf("%08lx %ld\n", offset - run, run);
+				}
+				run = 0;
 			}
-			run = 0;
+			offset++;
 		}
-		offset++;
 	}
 	if (ferror(input)) {
 		fprintf(stderr, "%s: can't read '%s': %s\n",