Not a typewriter

From Free net encyclopedia


"Not a typewriter" or ENOTTY is an error defined in errno.h indicating that there was an attempt to use a non-TTY device as a TTY device. Some people consider "Not a typewriter" to be a confusing error message. Some systems therefore display a different confusing error message such as "Inappropriate ioctl for device" instead. The real source of these confusing messages is, alas, more subtle.

This message is usually not the result of an error related to the I/O device, but was due to the way the isatty() library routine works. The error code errno is only set when a system call fails. One of the first system calls made by the C standard I/O library is in an isatty() call used to determine if the program is being run interactively by a human (in which case isatty() will succeed and the library will write its output a line at a time so the user sees a regular flow of text) or as part of a pipeline (in which case it writes a block at a time for efficiency). If a library routine fails for some reason unrelated to a system call (for example, because a user name wasn't found in the password file) and a naive programmer blindly calls the normal error reporting routine perror() on every failure, the leftover ENOTTY will result in an utterly inappropriate "Not a typewriter" (or "Not a teletype", or "Inappropriate ioctl for device) being delivered to the flabbergasted user.

Some very common UNIX mail software for many years had this bug: when mail was delivered from another system, the mail program was (of course) being run non-interactively. If the destination address was local, but referred to a user name not found in the local password file, the message sent back to the originator of the email was the startling announcement that the person they were attempting to communicate with was not a typewriter.

One is reminded of this exchange in The Fifth Element:

Police: Are you classified as human?
Korben Dallas: Negative, I am a meat popsicle. 

The Mac is not a typewriter is a book by Robin Williams.


Template:Nonfiction-book-stub