The C Standard Input/Output Library
The C standard input/output library represents files through a high-level interface called streams; this interface is exposed through the stdio.h
header. Streams are wrappers around bare files that implement buffered input and output, meaning that data accesses pass through an intermediate memory buffer in order to optimize data transfer between a program and external storage.
File System Model
The standard library implements a very simple file system model, where each file is identified by an arbitrary string called its file name, and contains arbitrary data as a sequence of bytes. The standard library provides mechanisms to delete, rename, and open files by their file names. Once opened, a stream may be read from, written to, repositioned, and closed.
Each stream has an end-of-file and error flag which may be set when certain operations fail; otherwise, the standard library provides no portable means of determining the cause of a failure. POSIX extends C in that is requires most standard I/O methods to set errno
(error number) to indicate the type of error on failure, so programs targeted to a POSIX system can take advantage of this additional information when it is available.
The standard library has no concepts of file system structure, directories, file type, ownership, access control, or other types of file metadata. Many types of specialty files, such as directories, support only a limited set of operations with standard library facilities.
Despite these limitations, the standard library is very useful for a wide variety of common system programming tasks, and can often coexist with direct file system access through system calls.