Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/12/84; site desint.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!mtuxo!mtunh!mtung!mtunf!ariel!vax135!petsd!pesnta!hplabs!sdcrdcf!trwrb!desint!geoff
From: geoff@desint.UUCP (Geoff Kuenning)
Newsgroups: net.bugs.4bsd,net.unix-wizards
Subject: Re: Bug in isatty (BSD4.2)
Message-ID: <112@desint.UUCP>
Date: Sat, 6-Jul-85 07:22:30 EDT
Article-I.D.: desint.112
Posted: Sat Jul  6 07:22:30 1985
Date-Received: Tue, 9-Jul-85 05:38:39 EDT
References: <726@mcvax.UUCP>
Reply-To: geoff@desint.UUCP (Geoff Kuenning)
Organization: SAH Consulting, Manhattan Beach, CA
Lines: 39
Xref: watmath net.bugs.4bsd:1592 net.unix-wizards:13748

In article <726@mcvax.UUCP> aeb@mcvax.UUCP (Andries Brouwer) writes:
>The following short C program
>
>main(){
>	extern int errno;
>
>	errno = 0;
>	putchar('\n');
>	if(errno > 0)
>		perror("perror");
>}
>
>gives unexpected results.
>E.g.
>	a.out | ...
>gives the error message "Operation not supported on socket".
>The reason is...[that putchar can leave errno nonzero even in nonerror cases]

Um, I think errno is specified to be valid only if putchar returns the
constant EOF.  Thus, the code should be:

	if (putchar ('\n') == EOF)
		perror ("putchar");

Incidentally, this brings up a bug in putc/putchar.  On both BSD and VMS,
the following code will print a message, even though the putchar succeeds:

	if (putchar ('\377') == EOF)
		fprintf (stderr, "you have the bug!\n");

The problem is that, in , the putc macro neglects to cast its
argument to an *unsigned* character, so it gets sign-extended on return
to -1.  The fix is easy;  I won't post it because (a) I don't have BSD
at my fingertips at the moment and (b) it's probably a licensing violation
anyway.
-- 

	Geoff Kuenning
	...!ihnp4!trwrb!desint!geoff