On 10/16/13, Edscott Wilson <[email protected]> wrote:
> I've been banging my head against the monitor for the past nine hours and
> narrowed a problem down to the following.
>  I've found that for certain data, the read() function will return a short
> byte count.
>
> Take the following test file: http://xffm.org/test.dbh and compile and
> execute the following program:
>
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> #include <errno.h>
>
>
> int main(int argc, char **argv){
>     int fd = open("test.dbh",O_RDWR);

Try adding O_BINARY to the open() flags here.


>     void *data = malloc(256);
>     size_t bytes = read(fd, data, 256);
>     printf("bytes read=%ld\n", (long)bytes);
>     printf("errno=%s\n", strerror(errno));
>     close(fd);
>         FILE *f = fopen("test.dbh", "r");
>     bytes = fread(data, 1, 256, f);
>     printf("bytes fread=%ld\n", (long)bytes);
>     return 1;
> }
>
>
> This is the output of the above program compiled with mingw gcc:
>
> bytes read=255
> errno=No error
> bytes fread=256
>
> Which is wrong. I get the same broken result with both:
> gcc.exe (rev5, Built by MinGW-W64 project) 4.8.1
> and
> gcc.exe (GCC) 4.6.2 (from mingw-32)
>
> Linux, of course, reads the 256 bytes correctly.
>
> So there is something in the file which breaks the read on Windows.
> What could possibly be wrong?
>  Is there some Windows trick you need apply to make read() work as it is
> intended?
>  Or would it be a bug of the mingw gcc port?
>
> Any help is appreciated.
>

--
O.S.

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to