Printf sets errno to 25?

daemon at houligan.UUCP daemon at houligan.UUCP
Fri Dec 20 07:07:24 AEST 1985


In article <119 at cpsc6a.UUCP>, peo at cpsc6a.UUCP (Paul E. Olson) writes:
> Could someone please explain to me why the printf() family of functions
> cause errno to be set to 25 (not a typewritter) when output is
> redirected to either a file or a pipe. I know that the problem comes
> from the C lib function isatty() when ioctl() fails. So, maybe the real
> question should be - Is this an oversight?

Once again, this discussion rears its ugly head.

Check your manual page "INTRO(2)" for how "errno" is to be used.
Specifically the phrase:
	"... errno should be tested ONLY after an error has occurred ..."
(emphasis added).

Please note that the value of "errno" upon return from a library routine is
specifically UNDEFINED unless:
	1.  The documentation for the routine specifically states that an
	    error code is returned in "errno" (this is untrue of the "printf"
	    family),
	2.  The routine DOES NOT RETURN an error condition (a return of -1 in
	    most cases).

What this all boils down to is:
	Don't examine the value contained in "errno" UNLESS the called
	routine specifically indicated an error has occurred by its return
	value.

--tgi
	while (--tgi)	/* my mind continues to decay */
		;	/* even though I do nothing.. */    

{brl-bmd,ccvaxa,pur-ee,sun}!csd-gould!midas!tgi (Craig Strickland @ Gould)
305/587-2900 x5014  CompuServe: 76545,1007   Source: BDQ615   MCIMail: 272-3350

(echo ".ft B"; echo ".ps 999"; echo "$disclaimer") | troff -t	# :-)



More information about the Comp.unix.wizards mailing list