From: ggp AT informix DOT com (Guy Gascoigne - Piggford) Subject: Re: fread fails when fopen is used without "rb" 14 Mar 1998 14:21:32 -0800 Message-ID: <3.0.3.32.19980313102529.018e6cf0.cygnus.gnu-win32@pop.pdx.informix.com> References: <199803121330 DOT HAA17235 AT chad DOT ccrl DOT mot DOT com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: cutts AT ccrl DOT mot DOT com, gnu-win32 AT cygnus DOT com At 07:30 AM 3/12/98 -0600, Kevin Cutts wrote: >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.) Well at first guess I'd say that the behaviour is correct on NT. Generally (since I don't know exactly what the cygnus lib does in this situation) one of the (perhaps unfortunate) differences between text mode and binary mode is that text mode will stop reading when it encounters certain characters, e.g a NUL or a ^Z. There is a definition of 'text-mode' that basically says that for the file to be readable it must contain lines of zero or more readable ASCII characters, where every line is terminated with a CR/LF (even the last line). Guy -- Guy Gascoigne - Piggford (ggp AT informix DOT com) Software Engineer, Informix Software, Inc. (Portland, Oregon) - 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".