| Did you know ... | Search Documentation: |
| Snew() |
IOSTREAM* from a handle, flags and a block of
callback functions. The flags argument is a bitwise or of
SIO_* flags. Flags that control the creation are:
SIO_INPUTSIO_OUTPUTSIO_NBUFSIO_LBUFSIO_FBUFSIO_NBUF), line buffered (SIO_LBUF)
or fully buffered (SIO_FBUF)SIO_TEXTENC_OCTET.SIO_RECORDPOSposition property and related predicates.SIO_NOMUTEX
If the stream is associated with an OS file handle the system
initializes the SIO_ISATTY flag (on POSIX systems) and if
possible tells the OS not to inherit this stream to child processes.
The symbol Sfilefunctions is a IOFUNCTIONS
struct that contains the callbacks for accessing a regular file. After
opening an file using the POSIX open() API we can create a stream
to this file using Snew():
int fno = open(path, O_RDONLY);
IOSTREAM *s;
if ( fno >= 0 )
s = Snew((void*)fno,
SIO_INPUT|SIO_FBUF|SIO_RECORDPOS|SIO_TEXT,
&Sfilefunctions);
...
Snew() can
only fail if there is not enough memory. In that case the return value
is NULL and errno is set to ENOMEM.