C file access question

Richard A. O'Keefe ok at goanna.cs.rmit.oz.au
Fri Sep 14 17:39:22 AEST 1990


In article <28 at screamer.csee.usf.edu>, stelmack at screamer.csee.usf.edu (Gregory M. Stelmack) writes:
> I've got some code I'm writing for ANSI file access [under SunOS 4.0.3]

> db = fopen("dd.data","rb+"); /* db is checked to make sure file opened */
                        ^^^

RTFM.  The SunOS 4.0.3 C compiler is _not_ ANSI compliant and Sun have
never pretended that it is.  If you read the manual page for fopen()
[- if you don't know how, here's all it takes:
	man fopen
] the manual page lists all the mode strings that Sun's fopen() understands,
and fb+ isn't one of them.  This "b" stuff is a kluge to work around the PC
convention of using two characters to end a line (ASCII has a "record
separator character", I've never understood why people didn't use that).
UNIX doesn't need it.  The simplest fix should be

		static char BinaryReadWriteMode[] =
	#ifdef	unix
			"r+";
	#else
			"rb+";
	#endif
		...
		db = fopen("dd.data", BinaryReadWriteMode);

-- 
Heuer's Law:  Any feature is a bug unless it can be turned off.



More information about the Comp.lang.c mailing list