[comp.lang.c] MSC 5.0 Bug???

C03601DM%WUVMD.BITNET@CUNYVM.CUNY.EDU (Derek Morgan) (02/08/88)

Is anybody aware of a bug in the fwrite() routine of MSC 5? If not, then
either I found one (highly unlikely), or my program is screwed up in some
subtle way (Extremely probable)...

gordan@maccs.UUCP (gordan) (02/08/88)

In article <11677@brl-adm.ARPA> C03601DM%WUVMD.BITNET@CUNYVM.CUNY.EDU (Derek Morgan) writes:
-Is anybody aware of a bug in the fwrite() routine of MSC 5? If not, then
-either I found one (highly unlikely), or my program is screwed up in some
-subtle way (Extremely probable)...

Perhaps your problem has something to do with the fact that newline is
two characters (CR LF) in MS-DOS, while C prefers it to be a single
character ('\n').

I think operating systems like MS-DOS use low-level routines to
automatically map between CR LF <--> '\n' if you open a file as a text
file.  However this can have counterintuitive results, e.g. if you do
     ftell (...)
     fread (N bytes)
     ftell (...)
your position in the file as reported by ftell will not necessarily have
been incremented by exactly N, due to the translation of two bytes into
one for CR LF.

Disclaimer: it's 5:30 am.  Any resemblance to fact is purely coincidental.

jrl@anuck.UUCP (j.r.lupien) (02/10/88)

Sorry to have to post this, the mailers didn't like the return path
they generated for me.

**message follows: ****

From: jrl%anuck%twitch%homxb%mtuxo@mtune.att.com
Date: Tue, 9 Feb  12:30:15 1988
Received: by mtune.ATT.COM (smail2.5)
	id AA22820; 9 Feb 88 12:30:15 EST (Tue)
To: twitch!homxb!mtuxo!mtune!rutgers!cmcl2!brl-adm!adm!C03601DM%WUVMD.BITNET@CUNYVM.CUNY.EDU
Subject: Re: MSC 5.0 Bug???
In-Reply-To: your article <11677@brl-adm.ARPA>

> Is anybody aware of a bug in the fwrite() routine of MSC 5? If not, then
> either I found one (highly unlikely), or my program is screwed up in some
> subtle way (Extremely probable)...

Hello,
   Perhaps you could be a bit more specific. I have used the fwrite
stuff, and found only one surprise: it does crlf translation by
default. You have to turn it off explicitly in your fopen call.
If that's not the problem, why don't you send me more specifics -
I would be willing to look at your source.

			-John Lupien
			(ihnp4|twitch)!mvuxa!anuxh!jrl

Kumar_Swaminathan.SVSantaClara@Xerox.COM (02/12/88)

In resp. to <983@maccs.UUCP> regarding a (possible)  bug in fwrite() of
msc:

Whether  or not  the CR/LF combo is interpreted as  '/n' depends on how one
opens the file with fopen.  If the "type" arg. in fopen  contains a 't' (for
text files) then such interpretation occurs. To avoid that use 'b' (for binary).
e.g:

fopen("File.name", "rb");         /* open  the file for read in binary mode and
*/
			                /* and  don't mess with CR/LF combos */

deest1@cisunx.UUCP (Duane E. Ellis) (02/19/88)

The problem you have with MSC, is MSC's BINARY I/O verses ASCII I/O
when you fopen() the file, make sure you are specing BINARY, other
wise, MSC is probably doing a newline map on you.

Example:

main()
{
FILE *fp, *fopen();
	fp=fopen("myfile","w");
	fwrite("\n",sizeof(char),1,fp); /* WRITE ONE CHAR ONLY!!! */
	flcose(fp);
}

In some cases, MSC will map the \n to \r\n, to match PC-DOS.
I Bet that's the problem you are seeing..