1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
.TH substdio 3
.SH NAME
substdio \- the Sub-Standard Input/Output Library
.SH SYNTAX
.B #include <substdio.h>
void \fBsubstdio_fdbuf\fP(&\fIs\fR,\fIop\fR,\fIfd\fR,\fIbuf\fR,\fIlen\fR);
int \fBsubstdio_fileno\fP(&\fIs\fR);
substdio \fIs\fR;
.br
int (*\fIop\fR)();
.br
int \fIfd\fR;
.br
char *\fIbuf\fR;
.br
int \fIlen\fR;
.SH DESCRIPTION
.B substdio
is the Sub-Standard I/O Library.
.B substdio
contains only a few of the features of stdio;
it is a fast, lightweight, low-level library,
suitable for use as a component of higher-level I/O libraries.
The point of
.B substdio
is to provide buffered I/O.
The basic object in
.B substdio
is the
.B substdio
structure;
a
.B substdio
variable stores
an operation,
a descriptor,
and
a pointer into a buffer of some nonzero length.
The
.B substdio
operations read data from the buffer,
filling the buffer as necessary using the operation on the descriptor,
or write data to the buffer,
flushing the buffer as necessary using the operation on the descriptor.
Input and output operations cannot be mixed.
.B substdio_fdbuf
initializes a
.B substdio
variable.
The operation is
.IR op .
The descriptor is
.IR fd .
The buffer is
.IR buf ,
an array of
.I len
chars.
.I op
will be called as
.I op\fR(\fIfd\fR,\fIx\fR,\fIn\fR).
Here
.I x
is a pointer to an array of characters of length
.IR n ;
.I op
must read some characters from
.I fd
to that array, or write some characters to
.I fd
from that array.
The return value from
.I op
must be the number of characters read or written.
0 characters read means end of input;
0 characters written means that the write operation
should be tried again immediately.
On error,
.I op
must return -1,
setting
.B errno
appropriately, without reading or writing anything.
Most errors are returned directly to the
.B substdio
caller, but an error of
.B error_intr
means that the operation should be tried again immediately.
There is a
.B SUBSTDIO_FDBUF
macro that can be used to statically initialize a
.B substdio
variable:
.EX
substdio s = SUBSTDIO_FDBUF(op,fd,buf,len);
.EE
.B substdio_fileno
returns the
descriptor for an initialized
.B substdio
variable.
.SH "SEE ALSO"
substdio_in(3),
substdio_out(3),
substdio_copy(3),
error(3)
|