sprintf(3s) query

Doug Gwyn gwyn at smoke.BRL.MIL
Sat Dec 17 06:46:02 AEST 1988


In article <878 at quintus.UUCP> ok at quintus.UUCP (Richard A. O'Keefe) writes:
-In article <9181 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
->#ifdef vax
->char	*sprintf();		/* too painful to do right */
->#endif
->Note that Sun MUST have changed this in order for it to apply to
->their (definitely non-VAX) machines.
-In point of fact, at least as of SunOS 3.2, they DIDN'T.
-So much for "MUST".  The effect is that in SunOS, if you wanted the
-buffer pointer, you had to explicitly declare sprintf() yourself.

I thought the poster who originated this discussion said that
his version of SunOS had done this.  I'm still covered by the
"in order for" clause in what I said.

->I hope by now all the BSD code that depends on the value of
->sprintf() being anything in particular has been changed to use
->some other method.  Usually, something like
->	buf[0] = '\0';
->	(void)sprintf(buf, fmt, args);
->	if (buf[0] == '\0')
->		/* error */
->is sufficient (it works with both definitions of sprintf()).
-Except that it doesn't work with either.  Consider
-	sprintf("%.*s", len, ptr);
-when len happens to be 0.  By the way, what _are_ the output error
-conditions that *printf() can detect other than by crashing?

Again, I said "Usually, ..." which implies "not always".  The vast
majority of sprintf() usage can correctly be changed to follow my
suggestion.  I note that you offered no alternative.

There are several possible errors other than I/O errors.  Think
hard enough and you should be able to imagine at least one.



More information about the Comp.lang.c mailing list