POSIX I/O to memory example
===========================
The POSIX I/O to memory example demonstrates how the POSIX I/O functions such as
open, close, read and write can be redirected to 'input' from and 'output' to a
memory buffer.
As ANSI I/O commands such as printf use the POSIX I/O layer, they too can be
redirected, so a printf and scanf with a memory buffer are also demonstrated.
Contents of the example
-----------------------
There is a single source file: memio.c. This contains implementations of what
it means to read, write, open and close a simple memory buffer device. There
are also some globals associated with the buffer: the buffer itself and read and
write offsets for the buffer (to act like file pointers would in a file).
The fundamental parts of the example are:
- creation of the underlying buffer operations buf_open(), buf_close(),
buf_read() and buf_write().
- creation of a dev_op_t structure to give the function names of our buffer
I/O operations.
- registration of the buffer device with a unique name and dev_id.
- opening of the buffer, making sure the underlying buf_open() function
copies it's 2nd dev_op_t argument into the device value of it's 1st fd_t
argument, so that the correct underlying I/O functions are used.
- POSIX I/O functions called on the buffer device will use the underlying
functions provided for I/O.
- ANSI I/O functions which are normally mapped to stdout, stderr, etc, can
be remapped to our buffer device by closing the normal output stream and
using the dup() function to duplicate our own file descriptor in its place.
Using the example
-----------------
To compile, use the line:
make <board_type>
where <board_type> may be one of the ones listed when you run your make tool
with no arguments.
To run the example, use the line:
st20run -t <board_name> memio.lku
where <board_name> is the name of your board.
Points to Note
--------------
This example does not perform full error checking an setting. For a
demonstration of the use of errno error setting and checking, see the minifs
example.