I'm trying to read a binary file on Windows 7 with a program compiled by MinGW. The binary file is ~10M in size but my program can only read less than 1000 bytes and it thinks it reached EOF.
Here is the code. I'm sure I'm doing something stupid but I just can't seem to find it.
#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #define TS_FILE "foo.data" int main(void) { int fd; int r; unsigned char buf[1024]; fd = open(TS_FILE, O_RDONLY|O_BINARY); printf("fd: %d\n", fd); if ( fd == -1 ) { exit(0); } for (;;) { r = read(fd, buf, 1000); if ( r != 1000 ) { printf("read error. %d\n", r); perror("read"); } if ( r == 0 ) { break; } } close(fd); } The program will say it reads 736 bytes and that's the EOF.
Could somebody tell me what is going on? Thanks!
Thanks,