Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Aug 2005 14:04:57 -0700
From:      Toby Peterson <toby@apple.com>
To:        freebsd-bugs@freebsd.org
Subject:   [PATCH] hexdump -s speedup on /dev
Message-ID:  <E0887C36-EC54-4A86-A21A-F1EF485EB171@apple.com>

next in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
This patch vastly increases the performance of hexdump -s <large  
offset> on devices. Test:

hexdump -s 100m /dev/ad0

- Toby
[-- Attachment #2 --]
? hexdump
? hexdump.1.gz
? od.1.gz
Index: display.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/hexdump/display.c,v
retrieving revision 1.22
diff -u -r1.22 display.c
--- display.c	4 Aug 2004 02:47:32 -0000	1.22
+++ display.c	29 Aug 2005 20:59:10 -0000
@@ -44,6 +44,7 @@
 
 #include <ctype.h>
 #include <err.h>
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -384,12 +385,13 @@
 			return;
 		}
 	}
-	if (S_ISREG(sb.st_mode)) {
-		if (fseeko(stdin, skip, SEEK_SET))
-			err(1, "%s", fname);
+	/* try to seek first; fall back on ESPIPE */
+	if (fseeko(stdin, skip, SEEK_SET) == 0) {
 		address += skip;
 		skip = 0;
 	} else {
+		if (errno != ESPIPE)
+			err(1, "%s", fname);
 		for (cnt = 0; cnt < skip; ++cnt)
 			if (getchar() == EOF)
 				break;

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E0887C36-EC54-4A86-A21A-F1EF485EB171>