[Robelle] [SmugBook] [Index] [Prev] [Next]

Advanced Programming in the UNIX Environment

by Richard Stevens

If you are writing software for UNIX you must get this book by Richard Stevens (Addison-Wesley, 1992 Amazon link). It is jam-packed with readable and illuminating programming examples.

Suppose you want your program to be aware of the type of terminal that is running it. If you look up "terminal" in the indexes of the three reference manuals for HP-UX, you'll find references to ttytype, tty, ttyname and terminfo. You read the brief and obscure man pages for these functions and you still don't have any idea how to use the information. If you look in Stevens' book, you find an index reference for "terminal identification", which contains the C source code for ttyname and isatty, clearly explained and with output from sample runs. As well, Stevens spells out the historical background and the implications you should watch out for. Here's an example:

POSIX.1 provides a run-time function that we can call to determine the name of the controlling terminal....Since most UNIX systems use /dev/tty as the name of the controlling terminal, this function is intended to aid portability to other operating systems....Two functions that are more interesting for a UNIX system are isatty, which returns true if a file descriptor refers to a terminal device, and ttyname, which returns the path name of the terminal device that is open on a file descriptor....The isatty function is trivial to implement...just try one of the terminal-specific functions (that doesn't change anything if it succeeds) and look at the return value.

Stevens' other books on UNIX and network topics are excellent also.

[Robelle] [SmugBook] [Index] [Unix] [Prev] [Next]