delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/06/19/04:22:46

To: Marty Leisner <leisner AT sdsp DOT mc DOT xerox DOT com>
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: O_TEXT/O_BINARY grief
Date: Sun, 19 Jun 94 10:25:12 +0300
From: eliz AT is DOT elta DOT co DOT il

> So why even bother?  Everything works and you have fewer
> portability problems if you treat everything as binary...

The problem is, DOS text lines have a CR-LF pair of characters as the
end-of-line marker.  When you read such a file in BINARY mode, these characters
are retained.  But programs written under Unix environment expect each line
to end with a single Newline (aka LF, aka \n) character, so they won't work.

Thus, if your program only reads TEXT files, then under MS-DOS you are better
off reading and writing them in TEXT mode (which is the default); then go32
will strip off all those unwanted CRs when reading and add them when writing,
and you source code will actually work unchanged under both DOS and Unix.  If,
on the other hand, your files MIGHT be binary, then you MUST read them in
binary mode and call the crlf2nl() library function to get rid of the CR
characters, if the file turns out to be text after all (you still can write the
file as TEXT, so the CRs will be added automagically).

This is admittedly not nice, but you could also say that whoever writes programs
which assume text and binary files are one and the same, as they are under Unix,
brought this trouble on us.

	Eli Zaretskii

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019