Re: [Mingw-w64-public] Short read mystery

2013-10-15 Thread Ozkan Sezer
On 10/16/13, Edscott Wilson edscott.wilson.gar...@gmail.com 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=60135031iu=/4140/ostg.clktrk
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] Short read mystery

2013-10-15 Thread niXman
 

Edscott Wilson писал 2013-10-16 03:07: 

 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 [1] 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);
 void *data = malloc(256);
 size_t bytes = read(fd, data, 256);
 printf(bytes read=%ldn, (long)bytes);
 printf(errno=%sn, strerror(errno));
 close(fd);
 FILE *f = fopen(test.dbh, r);

Maybe:
FILE *f = fopen(test.dbh, rb);

?

-- 
Regards, niXman
___
Dual-target(32  64-bit) MinGW compilers for 32 and 64-bit Windows:
http://sourceforge.net/projects/mingw-w64/
___
Another online IDE: http://liveworkspace.org/
 

Links:
--
[1] http://xffm.org/test.dbh
--
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=60135031iu=/4140/ostg.clktrk___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] Short read mystery

2013-10-15 Thread マーズ
Greetings Edscott Wilson,
In Unix, \r\n for a newline, versus '\n' in Windows?
Maybe a unix2dos the file would put everything in 
perspective?

Edscott Wilson 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);
 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.
 
 
 



--
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=60135031iu=/4140/ostg.clktrk
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public