diff options
| author | Kyle Evans <kevans@FreeBSD.org> | 2018-01-05 01:46:41 +0000 |
|---|---|---|
| committer | Kyle Evans <kevans@FreeBSD.org> | 2018-01-05 01:46:41 +0000 |
| commit | df7b0169fa9c527e30fb2494e965a71291fd7cd3 (patch) | |
| tree | 24974b4429c4dbe57c340f39cf8186d8ad12e3fc /usr.bin/hexdump | |
| parent | 09f07b001794bcc3cb51a13c85366492b8b6a826 (diff) | |
Notes
Diffstat (limited to 'usr.bin/hexdump')
| -rw-r--r-- | usr.bin/hexdump/display.c | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/usr.bin/hexdump/display.c b/usr.bin/hexdump/display.c index b2f57239722c..0b2df2e02805 100644 --- a/usr.bin/hexdump/display.c +++ b/usr.bin/hexdump/display.c @@ -39,6 +39,8 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/capsicum.h> +#include <sys/conf.h> +#include <sys/ioctl.h> #include <sys/stat.h> #include <capsicum_helpers.h> @@ -57,6 +59,7 @@ static off_t address; /* address/offset in stream */ static off_t eaddress; /* end address */ static void print(PR *, u_char *); +static void noseek(void); void display(void) @@ -386,7 +389,7 @@ next(char **argv) void doskip(const char *fname, int statok) { - int cnt; + int type; struct stat sb; if (statok) { @@ -398,16 +401,37 @@ doskip(const char *fname, int statok) return; } } - if (statok && S_ISREG(sb.st_mode)) { - if (fseeko(stdin, skip, SEEK_SET)) + if (!statok || S_ISFIFO(sb.st_mode) || S_ISSOCK(sb.st_mode)) { + noseek(); + return; + } + if (S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode)) { + if (ioctl(fileno(stdin), FIODTYPE, &type)) err(1, "%s", fname); - address += skip; - skip = 0; - } else { - for (cnt = 0; cnt < skip; ++cnt) - if (getchar() == EOF) - break; - address += cnt; - skip -= cnt; + /* + * Most tape drives don't support seeking, + * yet fseek() would succeed. + */ + if (type & D_TAPE) { + noseek(); + return; + } + } + if (fseeko(stdin, skip, SEEK_SET)) { + noseek(); + return; } + address += skip; + skip = 0; +} + +static void +noseek(void) +{ + int count; + for (count = 0; count < skip; ++count) + if (getchar() == EOF) + break; + address += count; + skip -= count; } |
