The C Programming Language, Ansi C
8.1 File Descriptors
Chapter 8 - The UNIX System Interface
The UNIX operating system provides its services through a set of
system
calls
, which are in effect functions within the operating system that may be
called by user programs. This chapter describes how to use some of the most
important system calls from C programs. If you use UNIX, this should be
directly helpful, for it is sometimes necessary to employ system calls for
maximum efficiency, or to access some facility that is not in the library.
Even if you use C on a different operating system, however, you should be
able to glean insight into C programming from studying these examples;
although details vary, similar code will be found on any system. Since the
ANSI C library is in many cases modeled on UNIX facilities, this code may
help your understanding of the library as well.
This chapter is divided into three major parts: input/output, file system, and storage allocation. The first two parts assume a modest familiarity with the external characteristics of UNIX systems.
Chapter 7 was concerned with an input/output interface that is uniform across operating systems. On any particular system the routines of the standard library have to be written in terms of the facilities provided by the host system. In the next few sections we will describe the UNIX system calls for input and output, and show how parts of the standard library can be implemented with them.
In the UNIX operating system, all input and output is done by reading or
writing files, because all peripheral devices, even keyboard and screen, are
files in the file system. This means that a single homogeneous interface
handles all communication between a program and peripheral devices.