Skip to content

Commit

Permalink
Fix hd command so it doesn't error out on EOF
Browse files Browse the repository at this point in the history
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 <[email protected]>

(cherry picked from commit a9fac41)

Change-Id: Ib2af725fc39e96c2f81559f61979d451604d4817
  • Loading branch information
Scott Anderson committed Jan 12, 2012
1 parent e437f55 commit 7e4c303
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion toolbox/hd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down

0 comments on commit 7e4c303

Please sign in to comment.