aboutsummaryrefslogtreecommitdiffstats
path: root/iceprog
diff options
context:
space:
mode:
authorRoland Lutz <rlutz@hedmen.org>2017-06-22 21:36:11 +0200
committerRoland Lutz <rlutz@hedmen.org>2017-07-02 14:49:37 +0200
commit0bd8876d7f5dad7abf8918b33d0d8e30d33b0aa0 (patch)
tree77cf6538054f65ccf71e5f68f8032324d824c114 /iceprog
parent47c9cd4ac1335f04ad84feae45f493b7db46bde8 (diff)
downloadicestorm-0bd8876d7f5dad7abf8918b33d0d8e30d33b0aa0.tar.gz
icestorm-0bd8876d7f5dad7abf8918b33d0d8e30d33b0aa0.tar.bz2
icestorm-0bd8876d7f5dad7abf8918b33d0d8e30d33b0aa0.zip
iceprog: Allow programming from standard input
Diffstat (limited to 'iceprog')
-rw-r--r--iceprog/iceprog.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/iceprog/iceprog.c b/iceprog/iceprog.c
index d5356b9..cd19ca0 100644
--- a/iceprog/iceprog.c
+++ b/iceprog/iceprog.c
@@ -472,7 +472,7 @@ int main(int argc, char **argv)
so we can fail before initializing the hardware */
FILE *f = NULL;
- int file_size = -1;
+ long file_size = -1;
if (test_mode)
/* nop */;
@@ -490,10 +490,13 @@ int main(int argc, char **argv)
"can't open '%s' for reading", filename);
if (!prog_sram && !check_mode && !dont_erase && !bulk_erase) {
- struct stat st_buf;
- if (stat(filename, &st_buf) == -1)
- err(EXIT_FAILURE, "can't stat '%s'", filename);
- file_size = (int)st_buf.st_size;
+ if (fseek(f, 0L, SEEK_END) == -1)
+ err(EXIT_FAILURE, "%s: fseek", filename);
+ file_size = ftell(f);
+ if (file_size == -1)
+ err(EXIT_FAILURE, "%s: ftell", filename);
+ if (fseek(f, 0L, SEEK_SET) == -1)
+ err(EXIT_FAILURE, "%s: fseek", filename);
}
}
@@ -659,7 +662,7 @@ int main(int argc, char **argv)
}
else
{
- fprintf(stderr, "file size: %d\n", file_size);
+ fprintf(stderr, "file size: %ld\n", file_size);
int begin_addr = rw_offset & ~0xffff;
int end_addr = (rw_offset + file_size + 0xffff) & ~0xffff;