jdp@killer.DALLAS.TX.US (Jim Pritchett) (11/27/88)
Could/would someone out there please tell me what the addition of a 'b' parameter to the mode means in the context of a fopen() call in Lattice C? I have Aztec C and it does not mention this at all. Neither does my K&R - unless I missed it somehow. If the above is less than clear, maybe an example will help. fopen(temp, "wb"); Thank you, Jim Pritchett killer!gtmvax!dms3b1!caleb!jdp preferred or killer!jdp
fgd3@jc3b21.UUCP (Fabbian G. Dufoe) (11/28/88)
From article <6241@killer.DALLAS.TX.US>, by jdp@killer.DALLAS.TX.US (Jim Pritchett): > Could/would someone out there please tell me what the addition of a 'b' parameter > to the mode means in the context of a fopen() call in Lattice C? > [for example] fopen(temp, "wb"); Lattice C allows you to modify the standard fopen() modes (r, w, a) with either an "a" or a "b". The "a" modifier means use Mode A to do translation on the files. Using Mode A each carriage return character ('\r') is deleted and CTRL-Z is treated as a logical end-of-file mark on reading. On writing each line feed character ('\n') is expanded to a carriage return followed by a line feed. Mode B doesn't do any translation. Mode A provides some MS-DOS compatibility. If you are translating source from Lattice to Aztec, just drop the "b" modifiers from the mode. --Fabbian Dufoe 350 Ling-A-Mor Terrace South St. Petersburg, Florida 33705 813-823-2350 UUCP: ...codas!usfvax2!jc3b21!fgd3 ...uunet!pdn!jc3b21!fgd3
bader+@andrew.cmu.edu (Miles Bader) (11/28/88)
jdp@killer.DALLAS.TX.US (Jim Pritchett) writes: > Could/would someone out there please tell me what the addition of a 'b' paramet\ > er > to the mode means in the context of a fopen() call in Lattice C? I have Aztec > C and it does not mention this at all. Neither does my K&R - unless I missed > it somehow. On the amiga, these modes are exactly the same as the default modes (without the 'b'). With some operating systems, like msdos, the default modes translate between CR/LF newlines (which the os uses) and LF newlines (which c programs use), and you need the 'b' modes to turn off this translation. But since the amiga os uses LF as newline, there's no need to ever do a translation in the amiga version. So they're there just to be compatible with other releases of the compiler. -Miles
wbnsnsr@nmtsun.nmt.edu (William Norris) (11/28/88)
In article <6241@killer.DALLAS.TX.US> jdp@killer.DALLAS.TX.US (Jim Pritchett) writes: >Could/would someone out there please tell me what the addition of a 'b' parameter >to the mode means in the context of a fopen() call in Lattice C? I have Aztec >C and it does not mention this at all. Neither does my K&R - unless I missed >it somehow. > >If the above is less than clear, maybe an example will help. > > fopen(temp, "wb"); The `b' stands for binary (versus `t' text) and does no translation on your file stream. In text mode, CR-LF sequences are translated to NL characters on input. On output, the reverse occurs: NL's are translated to CR-LF's. NOTE: This information was neither in K&R nor my Manx (Compiler :-) ) C. I looked it up in Microsoft C and I've used this mode in UNIX before. -- wbnsnsr@nmtsun.nmt.edu | /// Seulement William B. Norris IV |\\ /// l'Amiga peut POB #2185 C/S | \\// vous l'offrir. Socorro, NM 87801 |=-=-=-=-=-=-=-=-=-=-=-=-=
dillon@POSTGRES.BERKELEY.EDU (Matt Dillon) (11/28/88)
:> fopen(temp, "wb"); : :The `b' stands for binary (versus `t' text) and does no translation on :your file stream. In text mode, CR-LF sequences are translated to NL :characters on input. On output, the reverse occurs: NL's are translated :to CR-LF's. : :NOTE: This information was neither in K&R nor my Manx (Compiler :-) ) C. : I looked it up in Microsoft C and I've used this mode in UNIX before. On an IBM-PC, yes. The IBM-PC uses the CR-LF combinations instead of just an LF. Since STDIO defines the 'new line' to be just an LF, C implementations on the IBM's must filter out the CR's when reading and add them when writing. Unfortunetly, the idiots (not just Lattice, but essentially ALL the IBM-PC implementations) made the default 'text'. A simple fopen("blah", "r") on an IBM *assumes* translation, which is stupid. The default can usually be changed by modifying a global variable, but it doesn't make porting much easier. Even worse, the low-level IO routines as implemented on most C compilers on IBM's also do translation! On the Amiga, no. There is no translation done. There had better NOT be any translation! On the Amiga a 'new line' is a single LF which is compatible with STDIO (i.e. UNIX, which was what stdio was built on). A simple fopen("blah", "r") on the Amiga is 'binary', and there is no difference between binary and text. -Matt
toebes@sas.UUCP (John Toebes) (12/01/88)
In article <8811280644.AA14253@postgres.Berkeley.EDU> dillon@POSTGRES.BERKELEY.EDU (Matt Dillon) writes: > On an IBM-PC, yes. The IBM-PC uses the CR-LF combinations instead >of just an LF. Since STDIO defines the 'new line' to be just an LF, >C implementations on the IBM's must filter out the CR's when reading and >add them when writing. Unfortunetly, the idiots (not just Lattice, but >essentially ALL the IBM-PC implementations) made the default 'text'. Well, for almost ALL the programs that one finds in K&R (or Software Tools), this is a reasonable default. The correct solution could have been to make all files on the IBM have only a LF (actually a New-Line) at the end and then all would be fine. Personally, I think that the odds of this happening are about 0 (and maybe a little less) > A simple fopen("blah", "r") on an IBM *assumes* translation, which is stupid. >The default can usually be changed by modifying a global variable, but it >doesn't make porting much easier. > > Even worse, the low-level IO routines as implemented on most >C compilers on IBM's also do translation! This is because you must be able to SEEK on the file AS IF there were no CR/LF sequence. This causes much trouble when it comes to implementation. Oh yes, did I mention that people expect open, read and write as shown in K&R to work on MS-DOS with their standard text files with NO change? > > On the Amiga, no. There is no translation done. There had better >NOT be any translation! On the Amiga a 'new line' is a single LF which is >compatible with STDIO (i.e. UNIX, which was what stdio was built on). A >simple fopen("blah", "r") on the Amiga is 'binary', and there is no >difference between binary and text. > -Matt Have you looked at the implementation on the Amiga? If you did then you would see that there is not a translation. However, there are -people that expect, no make that DEMAND that the files they transferred over with XMODEM from a PC be readable on the Amiga in the same manner that they could be read under MS-DOS - WITHOUT them having to translate the file in the slightest. There is NO solution that satisfies everyone - only compromises. One should take the best default for the appropriate system to make the most people happy. /*---------------------All standard Disclaimers apply---------------------*/ /*----Working for but not officially representing SAS or Lattice Inc.-----*/ /*----John A. Toebes, VIII usenet:...!mcnc!rti!sas!toebes-----*/ /*------------------------------------------------------------------------*/