From aedbaa5c4d451859b0e8b470e9520f722915bda0 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 22 Apr 2024 22:14:23 +0000 Subject: [PATCH] xxd: buffer input via stdio. --- toys/other/xxd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/toys/other/xxd.c b/toys/other/xxd.c index 2afa5298..2a82d63f 100644 --- a/toys/other/xxd.c +++ b/toys/other/xxd.c @@ -41,17 +41,18 @@ GLOBALS( static void do_xxd(int fd, char *name) { + FILE *fp = xfdopen(xdup(fd), "r"); long long pos = 0; long long limit = TT.l; int i, j, k, len, space, c = TT.c ? : sizeof(toybuf); if (FLAG(s)) { - xlseek(fd, TT.s, SEEK_SET); + if (fseek(fp, TT.s, SEEK_SET)) perror_exit("seek %ld", TT.s); pos = TT.s; if (limit) limit += TT.s; } - while (0<(len = readall(fd, toybuf, (limit && limit-pos0){ if (!FLAG(p)) printf("%08llx: ", TT.o + pos); pos += len; space = 2*TT.c; @@ -84,6 +85,7 @@ static void do_xxd(int fd, char *name) } if (!TT.c && FLAG(p)) putchar('\n'); if (len<0) perror_exit("read"); + fclose(fp); } static void do_xxd_include(int fd, char *name) -- 2.39.2