Checking if it's a TTY
The program we will write here will check if stdout is a terminal. If it's not, it will print an error message.
Knowing how to check if stdin, stdout, or stderr are terminal devices will enable you to write error checks for programs that require a terminal to work.
For this recipe, we'll need the GCC compiler, the Make tool, and the generic Makefile. The generic Makefile can be downloaded from this chapter's GitHub folder, at https://github.com/PacktPublishing/Linux-System-Programming-Techniques/tree/master/ch9.
How to do it…
Here, we'll write a small program that prints an error message if stdout is not a terminal:
- Write the following small program in a file and save it as
ttyinfo.c. We use two new functions here. The first one is