From: Bob_McGowan AT xstor DOT com (Bob McGowan) Subject: RE: fread fails when fopen is used without "rb" 14 Mar 1998 14:22:33 -0800 Message-ID: <8B40B8756FA1D111BCB900A02495E24F0154A5.cygnus.gnu-win32@Neptune.xstor.com> Mime-Version: 1.0 Content-Type: text/plain To: gnu-win32 AT cygnus DOT com Kevin, This is a "feature" and even DOS tools (copy in particular) can have this problem. It comes from the fact that it text mode, a litteral control-z character is entered in the file to mark EOF. You can prove this by using copy to creat a text file (note just means the return key): copy con file text text text ^Z and copy reports it copied one file. If a binary file is opened in text mode, the first control-z seen will now indicate EOF and the read will return indicating EOF. This is why the DOS copy command, when used to paste together multiple binary file pieces, is run with the /b option, to force binary mode: copy /b xa+xb+xc file.zip ---- Bob McGowan i'm bobmcgow at xstor dot com Storage Dimensions, Inc. -----Original Message----- From: Kevin Cutts [mailto:cutts AT ccrl DOT mot DOT com] Sent: Thursday, March 12, 1998 5:31 AM To: gnu-win32 AT cygnus DOT com Subject: fread fails when fopen is used without "rb" I made a mistake and opened a binary file using fopen("file","r"). Note that I forgot to open it with "rb". When I read the file, I could only read part of the file: the read only suceeded for 2081 bytes of the 345K! Believing that I had made a coding mistake, I tried 'wc'. It agreed with my code: they both 'think' the file has 2081 bytes. However emacs and ls both realize the file is much larger. (When I used a truly ascii file, the size worked correctly. The code hack does work correctly under the Metrowerks compiler.) Does this seem like the correct behaviour? I can't trust wc because it obviously opens as text. I looked in the faq without seeing anything that suggests this operation. In this case the failure was the best thing that could have happened because I discovered that the legacy unix code needs some work around the binary/text problems. PS. I have the binary file which exhibits this problem if anyone is interested. -- Kevin M. Cutts IL02-2928 Motorola, Inc., CCR&D Email ckc006 -at- email.mot.com 1301 E. Algonquin Rd. Work (847) 576-9056 Schaumburg, IL 60196 - For help on using this list (especially unsubscribing), send a message to "gnu-win32-request AT cygnus DOT com" with one line of text: "help". - For help on using this list (especially unsubscribing), send a message to "gnu-win32-request AT cygnus DOT com" with one line of text: "help".