Printf sets errno to 25?

Andy Merritt apm at iclbra.UUCP
Wed Dec 18 04:29:13 AEST 1985


> *** REPLACE THIS LINE WITH YOUR MESSAGE ***
> 
> 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? It would seem to me that redirecting

The problem is a common misunderstanding about the use of errno. The value
in errno is useful if, and only if, the call has returned a value indicating
failure. This value is commonly -1, and sometimes NULL for functions 
returning pointers. The Intro(2) manual page says: "Errno is not cleared on
successful calls, so it should be tested only after an error has been indicated"

The documentation I have for printf further states that it, fprintf and sprintf
return the number of characters transmitted, or a negative value if an output
error was encountered.
 
Hope this helps.
		UUCP: ...seismo!mcvax!ukc!stc!iclbra!apm
		MAIL: Andrew Merritt, ICL, Lovelace Rd, Bracknell, Berkshire



More information about the Comp.unix.wizards mailing list