summaryrefslogtreecommitdiff
path: root/nandwrite.c
diff options
context:
space:
mode:
authorJehan Bing <jehan@orb.com>2009-08-05 17:40:42 -0700
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2009-08-11 16:14:20 +0300
commit8c7e9e0936fcb18f1c95e618c2a2bb138a3c9e35 (patch)
treec0ecae8f2f83e6b2ad683c54c52ee90649e666f5 /nandwrite.c
parentb0eab860c9b68b74d108836041346544d925fc9f (diff)
nandwrite: unified reading from standard input and from file - part2
Use the same code structure when reading the OOB than when reading the regular data. Signed-off-by: Jehan Bing <jehan@orb.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'nandwrite.c')
-rw-r--r--nandwrite.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/nandwrite.c b/nandwrite.c
index 3695c20..f6bff60 100644
--- a/nandwrite.c
+++ b/nandwrite.c
@@ -520,17 +520,32 @@ int main(int argc, char * const argv[])
}
if (writeoob) {
- int tinycnt = 0;
+ {
+ int readlen = meminfo.oobsize;
- while(tinycnt < meminfo.oobsize) {
- cnt = read(ifd, oobreadbuf + tinycnt, meminfo.oobsize - tinycnt);
- if (cnt == 0) { // EOF
- break;
- } else if (cnt < 0) {
- perror ("File I/O error on input file");
+ int tinycnt = 0;
+
+ while (tinycnt < readlen) {
+ cnt = read(ifd, oobreadbuf + tinycnt, readlen - tinycnt);
+ if (cnt == 0) { // EOF
+ break;
+ } else if (cnt < 0) {
+ perror ("File I/O error on input");
+ goto closeall;
+ }
+ tinycnt += cnt;
+ }
+
+ if (tinycnt < readlen) {
+ fprintf(stderr, "Unexpected EOF. Expecting at least "
+ "%d more bytes for OOB\n", readlen - tinycnt);
goto closeall;
}
- tinycnt += cnt;
+
+ if ((ifd == STDIN_FILENO) && (cnt == 0)) {
+ /* No more bytes - we are done after writing the remaining bytes */
+ imglen = 0;
+ }
}
if (!noecc) {