vdudouyt / stm8flash

program your stm8 devices with SWIM/stlinkv(1,2)
GNU General Public License v2.0
403 stars 183 forks source link

Use "wb" as fopen flag for Windows compatibility #116

Closed HiFiPhile closed 5 years ago

HiFiPhile commented 5 years ago

It turns out in Windows, if "w" is used as fopen flag, line break will be added to the file written when fwrite is called. That's why I got a file of 32800+ bytes when reading a 32k device.

if(!(f = fopen(filename, "wb"))) spawn_error("Failed to open file"); switch(fileformat) { case INTEL_HEX: ihex_write(f, buf, start, start+bytes_count); break; case MOTOROLA_S_RECORD: srec_write(f, buf, start, start+bytes_count); break; default: fwrite(buf, 1, bytes_count, f); }

spth commented 5 years ago

If added the "b" when operating on binary files. Please check if this works for you now.

Philipp

HiFiPhile commented 5 years ago

In my case it solved my issue, I'm using latest Mingw under Windows 10.