The standard C library provides several interfaces to the basic I/O support provided by the underlying operating system. These include the open, read, write, close interfaces for unbuffered unformatted I/O, fread, fopen, fread and fwrite for buffered unformatted I/O as well as the fprintf, fscanf interfaces for buffered formatted I/O. Most imlementations will eventually depend on the open, read, write, close system calls provided by the underlying operating system to implement all of the other interfaces.
Many of the embedded systems programs run in an environment where either there is no underlying operating system or any operating system present has limited support for I/O. Fortunately, most embedded systems development tools still provide a I/O library that can be used on embedded systems with little additional effort by the programmer.
In the rest of this seminar we will discuss the following:
* Unformatted Unbuffered I/O open, read, write, close, lseek * Unformatted Buffered I/O fopen, fread, fwrite, fclose and fseek * Formatted Buffered I/O fprintf, fscanf, sprintf, sscanf
Unformatted Unbuffered I/O
The functions open, read, write close provide a direct interface to the underlying operating system functions (system calls) for file open, file read, file write and file close operations.
Embedded Systems Considerations: How does one implement open, read, write, close without an operating system ? Debugging considerations. Customizable libraries. Examples
Unformatted Buffered I/O
The functions fopen, fwrite, fread, fclose add a layer of buffering above the read, write interfaces. Using setvbuf.
Embedded Systems Considerations: Initializing stdout, stdin and stderr. What is standard input on an embedded system ? What about stderr on a satellite ? Concepts: Does buffering always work ? Line Buffering. Examples:
Formatted Buffered I/O
The functions fprintf, fscanf provide the highest level of I/O support in the C library. All these functions depend on the lower level unformatted buffered I/O functions fwrite and fread.
Embedded Systems Considerations: Support For formatting float and double values. Memory considerations. Internationalization Support Examples