Article View: comp.os.os2.programmer
Article #502Re: fopen(f,"r") vs fopen(f,"rb") what's the diff?
From: dave
Date: Mon, 27 Jul 1992 14:53
Date: Mon, 27 Jul 1992 14:53
36 lines
2075 bytes
2075 bytes
<1992Jul25.175848.29166@unixg.ubc.ca>
In <1992Jul25.175848.29166@unixg.ubc.ca> ochealth writes:
> A number of UNIX programs I have ported to OS/2 using emx or gcc
> choke on binary files, unless I modify them.
>
> for example:
> f = fopen(name,"r") must be changed to f=fopen(name,"rb")
> etc.
>
> I was wondering just what happens when you don't open as binary.
> Will it return EOF when it sees ^Z or what?
Opening a file in text mode on OS/2 will cause CR/LF (\r\n) to be turned
into a single LF (\n) character, and will cause the EOF flag to be set
when reading a ^Z (\x1a).
> This is sort of troubling to me, since EMX is desing to make porting UNIX easier
>
> Was fopen changed to make it more compatible with OS/2 or what. From what I've
> read "r" and "rb" are handled the same in UNIX.
The original Unix utilities should *really* have opened files in binary
mode in the first place. The way that Unix works causes binary mode to
be identical to text mode, so the utilities' authors got away with
reading binary as text on Unix systems -- the two modes are the same, so
it doesn't matter which one you use. On OS/2, there *is* a difference,
so you have to be more careful. If the utilities treat files as binary,
then by all means, change the code so that the fopen() call uses "rb".
dave
-------------------------------------------------------------------------
Dave Mooney dmm@vnet.ibm.com
C Set/2 Development, IBM Canada Lab, 844 Don Mills Rd, Toronto, Ontario
"If you've got a blacklist, I want to be on it"
Technical Details
Message-ID:
<19920727.080118.726@almaden.ibm.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!vnet.ibm.comReferences:
<=!jmdvp.feustel@netcom.com> <92Jul25.163359.18069@acs.ucalgary.ca>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!vnet.ibm.com From: dmm@vnet.ibm.com (dave) Message-ID: <19920727.080118.726@almaden.ibm.com> Date: Mon, 27 Jul 92 10:53:09 EDT Newsgroups: comp.os.os2.programmer Subject: Re: fopen(f,"r") vs fopen(f,"rb") what's the diff? Organization: IBM Canada Lab News-Software: UReply 3.0 X-X-From: dmm@vnet.ibm.com (Dave Mooney) References: <=!jmdvp.feustel@netcom.com> <92Jul25.163359.18069@acs.ucalgary.ca> Lines: 36