Not a typewriter

Dave Martindale dave at onfcanim.UUCP
Fri Jun 20 14:07:25 AEST 1986


In article <717 at axis.UUCP> philip at axis.UUCP (Philip Peake) writes:
>In article <542 at codas.ATT.UUCP> mikel at codas.UUCP writes:
>>> What does the sys_errlist message 'Not a typewriter' *really* mean??
>>
>
>This is true. *However*, if you look at the documentation *carefully*, you
>will find that it says that errno is only valid if the system call preceeding
>it returned an error value.
>
>I agree that this is a disgusting state of affairs, and I have recently
>had problems with a code segment as follows:
>
>
>	fp = fopen(.....);
>	errno = 0;
>	..
>	..
>	loop: fwrite(.....);
>	if (errno != 0) /* a write problem occured */
>	{
>		...
>		...
>	}
>	..
>
>This bombed out complaining about "Not a teletype", there was in fact,
>no problem at all. The code came from a BSD4.? system, the machine on
>which the problems occured runs S5.2.

Right.  As the manual says, errno is meaningful only after a system call
has failed.  If you want to check for an error in the fwrite, either check
fwrite's return value, or use ferror().

Errno is meaningful at the level of doing system calls - read, write, etc.
Fwrite is a higher-level function, and has its own ways of indicating errors.

In fact, in this particular case, errno is being set as a side effect of
the fwrite.  The first time you do I/O on a stdio unit, the package does
an ioctl("get terminal characteristics") on the file descriptor.  If the
ioctl succeeds, stdio knows that it should line-buffer or character-buffer
that stream.  If the ioctl fails (and when it does, it will set errno to
"not a typewriter"), stdio will use block buffering appropriate to a file.

Because of this, "not a typewriter" is the error message you will almost always
see if you look at errno when there hasn't been a real error, since almost
every program does I/O through stdio fairly early.

The moral is: you *can't* reliably tell whether there has been an error by
checking an external variable every once in a while.  You have to check
the return value of everyting that could possibly go wrong.



More information about the Comp.unix mailing list