summaryrefslogtreecommitdiffstats
path: root/toolbox/hd.c
diff options
context:
space:
mode:
authorScott Anderson <saa@google.com>2012-01-12 14:01:43 -0800
committerScott Anderson <saa@google.com>2012-01-12 15:17:07 -0800
commit7e4c303fe0f490be04400f3f3a08f0c4f5553a96 (patch)
tree755759f04db1ae1ecfdc74a0d6107e715da48bc0 /toolbox/hd.c
parente437f552d2e6a2e6874340754fc59c310d52e91b (diff)
downloadsystem_core-7e4c303fe0f490be04400f3f3a08f0c4f5553a96.zip
system_core-7e4c303fe0f490be04400f3f3a08f0c4f5553a96.tar.gz
system_core-7e4c303fe0f490be04400f3f3a08f0c4f5553a96.tar.bz2
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. Signed-off-by: Scott Anderson <saa@google.com> (cherry picked from commit a9fac4155f645b59d92028d56af573999051ab70) Change-Id: Ib2af725fc39e96c2f81559f61979d451604d4817
Diffstat (limited to 'toolbox/hd.c')
-rw-r--r--toolbox/hd.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/toolbox/hd.c b/toolbox/hd.c
index da31245..0d2f96a 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;
}