--- /dev/null
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+
+char buf[65536];
+
+void findnulls(int fd, char *source, int squelch)
+{
+ int i, ret, n, s, off;
+
+ n = 0;
+ s = -1;
+ off = 0;
+ while(1) {
+ ret = read(fd, buf, sizeof(buf));
+ if(ret < 0) {
+ if(source != NULL)
+ perror(source);
+ else
+ perror("read");
+ return;
+ }
+ for(i = 0; i < ret; i++) {
+ if(buf[i] == 0) {
+ if(s == -1)
+ s = off + i;
+ n++;
+ } else {
+ if(n > 0) {
+ if(n > squelch) {
+ if(source == NULL)
+ printf("%i %i\n", s, n);
+ else
+ printf("%s: %i %i\n", source, s, n);
+ }
+ s = -1;
+ n = 0;
+ }
+ }
+ }
+ off += ret;
+ if(ret == 0)
+ break;
+ }
+ if(n > squelch) {
+ if(source == NULL)
+ printf("%i %i\n", s, n);
+ else
+ printf("%s: %i %i\n", source, s, n);
+ }
+}
+
+int main(int argc, char **argv)
+{
+ int i, c;
+ int squelch;
+ int fd;
+
+ squelch = 1024;
+ while((c = getopt(argc, argv, "hs:")) >= 0) {
+ switch(c) {
+ case 's':
+ squelch = atoi(optarg);
+ break;
+ case 'h':
+ case '?':
+ case ':':
+ default:
+ fprintf(stderr, "usage: findnulls [-h] [-s squelch] [FILE...]\n");
+ exit((c == 'h')?0:1);
+ }
+ }
+ if(optind < argc) {
+ for(i = optind; i < argc; i++) {
+ if((fd = open(argv[i], O_RDONLY)) < 0) {
+ perror(argv[i]);
+ continue;
+ }
+ findnulls(fd, argv[i], squelch);
+ close(fd);
+ }
+ } else {
+ findnulls(0, NULL, squelch);
+ }
+ return(0);
+}
+
+/*
+ * Local Variables:
+ * compile-command: "gcc -Wall -g -o findnulls findnulls.c"
+ * End:
+ */