Skip to Content
UNIX Filesystems: Evolution, Design, and Implementation
book

UNIX Filesystems: Evolution, Design, and Implementation

by Steve D. Pate
January 2003
Intermediate to advanced content levelIntermediate to advanced
480 pages
13h 22m
English
Wiley
Content preview from UNIX Filesystems: Evolution, Design, and Implementation

Standard Input, Output, and Error

The standard input, output, and error for a process can be referenced by the file descriptors STDIN_FILENO, STDOUT_FILENO, and STDERR_FILENO. To use the stdio library routines on either of these files, their corresponding file streams stdin, stdout, and stderr can also be used. Here are the definitions of all three:

extern FILE *stdin;
extern FILE *stdout;
extern FILE *stderr;

All three file streams can be accessed without opening them in the same way that the corresponding file descriptor values can be accessed without an explicit call to open().

There are some standard I/O library routines that operate on the standard input and output streams explicitly. For example, a call to printf() uses stdin by default whereas a call to fprintf() requires the caller to specify a file stream. Similarly, a call to getchar() operates on stdin while a call to getc() requires the file stream to be passed. The declaration of getchar() could simply be:

#define getchar()   getc(stdin)
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Design and Implementation of the FreeBSD Operating System, 2nd Edition

Design and Implementation of the FreeBSD Operating System, 2nd Edition

Marshall Kirk McKusick, George V. Neville-Neil, Robert N.M. Watson

Publisher Resources

ISBN: 9780471456759Purchase book