Printf sets errno to 25?
Paul E. Olson
peo at cpsc6a.UUCP
Fri Dec 13 05:55:33 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
printf output does not constitute an error and that the functions _findbuf()
and setbuf() should take care to reset errno to 0 if line buffering is not
needed. At first I thought it was a bug, but now I'm not so sure. I get the
same results using:
SYS 5.0.5 on a 3B20
SYS 5.2 on a 3B5
SYS 5.2 on a 3B2
Xenix 3.0 on an Altos
4.2BSD on an 11/780
AT&T PC7300
The following illustrates the problem.
/* foo.c */
extern int errno;
main()
{
printf("errno=%d\n", errno);
printf("errno=%d\n", errno);
}
$ cc foo.c -o foo
$ foo
errno=0
errno=0
$ foo >bar
$ cat bar
errno=0
errno=25
$
All this started while chasing a bug is some software I was porting.
Thanks in advance for any and all comments.
Paul E. Olson
ihnp4!cpsc6a!peo
More information about the Comp.unix.wizards
mailing list