If the fread didn't read all in one go, the buffer was being repeatedly overwritten from the start instead of continuing the read :-/
I also changed the overall approach in some respects.
If the fread didn't read all in one go, the buffer was being repeatedly overwritten from the start instead of continuing the read :-/
I also changed the overall approach in some respects.