summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2013-10-26 11:59:14 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2013-10-26 11:59:14 (GMT)
commitfedecab8255ecf25ce20b3632cab5bcd586c1f94 (patch)
tree6a0e050086ac79a4053d0b347bfb22a879982f5d
parent2e2227f2b1c291f3d7df86024be91c205f7b9386 (diff)
downloadabc80sim-fedecab8255ecf25ce20b3632cab5bcd586c1f94.zip
abc80sim-fedecab8255ecf25ce20b3632cab5bcd586c1f94.tar.gz
abc80sim-fedecab8255ecf25ce20b3632cab5bcd586c1f94.tar.bz2
abc80sim-fedecab8255ecf25ce20b3632cab5bcd586c1f94.tar.xz
fileop: make it possible to get the exact size of a file
Include the number of excess bytes in the last logical block, to make it possible to obtain the exact size of a file if desired. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--fileop.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/fileop.c b/fileop.c
index d259c38..56bf023 100644
--- a/fileop.c
+++ b/fileop.c
@@ -426,8 +426,10 @@ static void do_input(uint16_t ix)
}
}
if (de) {
- dlen += sprintf(data1+2+dlen, ",%lu\r\n",
- ((unsigned long)st.st_size + 252)/253);
+ unsigned long blocks = (st.st_size + 252)/253;
+ unsigned long pad = 253*blocks - st.st_size;
+ /* pad = unused bytes in the last block */
+ dlen += sprintf(data1+2+dlen, ",%lu,%lu\r\n", blocks, pad);
err = 0;
} else {
err = 128+34;