X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=support%2Fmakebin%2Fmakebin.c;h=b6acaf4c872dde008a089962a2be76a78aa29499;hb=f3a44fc094dc5ce393e2029d3c7c6587a4b1a835;hp=deb4e78febf8e8534d8c91066ff0cd7876343fb3;hpb=11e3839c21831fa11d5508b05a57320e02f12330;p=fw%2Fsdcc diff --git a/support/makebin/makebin.c b/support/makebin/makebin.c index deb4e78f..b6acaf4c 100644 --- a/support/makebin/makebin.c +++ b/support/makebin/makebin.c @@ -1,8 +1,16 @@ /** @name makebin - turn a .ihx file into a binary image. */ +#include #include #include #include +#include + +#if defined(__BORLANDC__) || defined(__MINGW32__) || defined(__CYGWIN__) + #include + #include +#endif + typedef unsigned char BYTE; @@ -29,16 +37,27 @@ void usage(void) "Usage: makebin [-p] [-s romsize] [-h]\n"); } +void fixStdout(void) +{ + #if defined(__BORLANDC__) || defined(__MINGW32__) || defined(__CYGWIN__) + setmode(fileno(stdout), O_BINARY); + #endif +} + + int main(int argc, char **argv) { int size = 32768, pack = 0, real_size = 0; BYTE *rom; + size_t res; char line[256]; char *p; argc--; argv++; + fixStdout(); + while (argc--) { if (**argv != '-') { usage(); @@ -95,10 +114,13 @@ int main(int argc, char **argv) real_size = addr; } - if (pack) - fwrite(rom, 1, real_size, stdout); - else - fwrite(rom, 1, size, stdout); + if (pack) { + res = fwrite(rom, 1, real_size, stdout); + assert(res == real_size); + } else { + res = fwrite(rom, 1, size, stdout); + assert(res == size); + } return 0; }