From a9fac4155f645b59d92028d56af573999051ab70 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Thu, 12 Jan 2012 14:01:43 -0800 Subject: [PATCH] Fix hd command so it doesn't error out on EOF hd would error out on files that were not a multiple of its read buffer size (4096). For example: Read error on init.rc, offset 17040 len 4096, No such file or directory The fix is to stop reading on EOF instead of treating it as an error. Change-Id: Ie7f4216e08835150f2f5784e77bb9e2190b0def4 Signed-off-by: Scott Anderson --- toolbox/hd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/toolbox/hd.c b/toolbox/hd.c index da312452b..0d2f96af5 100644 --- a/toolbox/hd.c +++ b/toolbox/hd.c @@ -68,6 +68,8 @@ int hd_main(int argc, char *argv[]) if(count > 0 && base + count - filepos < read_len) read_len = base + count - filepos; res = read(fd, &buf, read_len); + if(res == 0) + break; for(i = 0; i < res; i++) { if((i & 15) == 0) { printf("%08x: ", filepos + i); @@ -80,7 +82,7 @@ int hd_main(int argc, char *argv[]) lsum = 0; } } - if(res <= 0) { + if(res < 0) { printf("Read error on %s, offset %d len %d, %s\n", argv[optind], filepos, read_len, strerror(errno)); return 1; }