mirror of /home/gitosis/repositories/libowfat.git

31 changed files with 477 additions and 17 deletions
@ -0,0 +1,37 @@
|
||||
.TH buffer 3 |
||||
.SH NAME |
||||
buffer.h \- generic read/write buffering |
||||
.SH SYNTAX |
||||
.B #include <buffer.h> |
||||
|
||||
buffer* buffer_0; /* like stdio's stdin */ |
||||
buffer* buffer_1; /* like stdio's stdout */ |
||||
buffer* buffer_2; /* like stdio's stderr */ |
||||
|
||||
.SH DESCRIPTION |
||||
buffer.h provides a generic buffer interface that can be used for |
||||
read and write buffering. Buffers must be initialized with |
||||
\fBbuffer_init\fR. |
||||
|
||||
A buffer can only be used for reading or writing at the same time, not |
||||
both. |
||||
|
||||
Unlike stdio, these write buffers are not flushed automatically at |
||||
program termination; you must manually call \fBbuffer_flush\fR, |
||||
\fBbuffer_putsflush\fR, \fBbuffer_putflush\fR or |
||||
\fBbuffer_putnlflush\fR. |
||||
|
||||
.SH EXAMPLE |
||||
See buffer_init(3) for example read buffer code. Here is typical code |
||||
for printing an error message on stderr: |
||||
|
||||
#include <buffer.h> |
||||
|
||||
buffer_puts(buffer_2,"error: got only "); |
||||
buffer_putulong(buffer_2,got); |
||||
buffer_puts(buffer_2," bytes, but expected at least "); |
||||
buffer_putulong(buffer_2,expected); |
||||
buffer_putsflush(buffer_2," bytes!"); |
||||
|
||||
.SH "SEE ALSO" |
||||
buffer_init(3), buffer_put(3), buffer_get(3), buffer_flush(3) |
@ -0,0 +1,14 @@
|
||||
.TH buffer_feed 3 |
||||
.SH NAME |
||||
buffer_feed \- low-level component of buffer_get |
||||
.SH SYNTAX |
||||
.B #include <buffer.h> |
||||
|
||||
int \fBbuffer_feed\fP(buffer* \fIb\fR); |
||||
.SH DESCRIPTION |
||||
If the string is nonempty, buffer_feed returns the length of the string. |
||||
If the string is empty, buffer_feed uses the read operation to feed data |
||||
into the string; it then returns the new length of the string, or 0 for |
||||
end of input, or -1 for error. |
||||
.SH "SEE ALSO" |
||||
buffer_init(3), buffer_get(3), buffer_peek(3), buffer_feed(3), buffer(3) |
@ -0,0 +1,27 @@
|
||||
.TH buffer_flush 3 |
||||
.SH NAME |
||||
buffer_flush \- feed buffer to write function |
||||
.SH SYNTAX |
||||
.B #include <buffer.h> |
||||
|
||||
int \fBbuffer_flush\fP(buffer* \fIb\fR); |
||||
.SH DESCRIPTION |
||||
buffer_flush feeds a string \fId\fR[0], \fId\fR[1], ..., |
||||
\fId\fR[\fIdlen\fR-1] to the write operation by calling |
||||
|
||||
\fBop\fR(\fIfd\fR,\fId\fR,\fIdlen\fR) |
||||
|
||||
If \fBop\fR successfully handles one or more bytes at the beginning of |
||||
the string, it must return the number of bytes handled; if this number |
||||
is smaller than \fIdlen\fR, buffer_flush will call \fBop\fR again with |
||||
the rest of the string. If \fBop\fR does not handle any bytes, and does |
||||
not encounter an error, it must return 0, or return -1 with \fIerrno\fR |
||||
set to EINTR; in either case, buffer_flush will immediately call \fBop\fR |
||||
again. If \fBop\fR encounters an error, it must return -1 with errno set to |
||||
something other than EINTR; buffer_flush will pass the error to the |
||||
caller. |
||||
|
||||
On success, buffer_flush returns 0. On error, buffer_flush returns -1, |
||||
setting \fIerrno\fR appropriately. |
||||
.SH "SEE ALSO" |
||||
buffer_init(3) |
@ -0,0 +1,26 @@
|
||||
.TH buffer_get 3 |
||||
.SH NAME |
||||
buffer_get \- read binary data from buffer |
||||
.SH SYNTAX |
||||
.B #include <buffer.h> |
||||
|
||||
int \fBbuffer_get\fP(buffer* \fIb\fR,char* \fIx\fR,unsigned int \fIlen\fR); |
||||
.SH DESCRIPTION |
||||
Normally buffer_get copies data to \fIx\fR[0], \fIx\fR[1], ..., |
||||
\fIx\fR[\fIlen\fR-1] from the beginning of a string stored in |
||||
preallocated space; removes these \fIlen\fR bytes from the string; and |
||||
returns \fIlen\fR. |
||||
|
||||
If, however, the string has fewer than \fIlen\fR (but more than 0) |
||||
bytes, buffer_get copies only that many bytes, and returns that number. |
||||
|
||||
If the string is empty, buffer_get first uses a \fBread operation\fR to |
||||
feed data into the string. The \fBread operation\fR may indicate end of |
||||
input, in which case buffer_get returns 0; or a read error, in which |
||||
case buffer_get returns -1, setting \fIerrno\fR approporiately. |
||||
|
||||
The preallocated space and the \fBread operation\fR are specified by |
||||
\fIb\fR. You must initialize \fBb\fR using buffer_init before calling |
||||
buffer_get (or use the pre-initialized buffer_0). |
||||
.SH "SEE ALSO" |
||||
buffer_init(3), buffer_feed(3), buffer_peek(3), buffer_seek(3), buffer(3) |
@ -0,0 +1,27 @@
|
||||
.TH buffer_get_token 3 |
||||
.SH NAME |
||||
buffer_get_token \- read token from buffer |
||||
.SH SYNTAX |
||||
.B #include <buffer.h> |
||||
|
||||
int \fBbuffer_get_token\fP(buffer* \fIb\fR,char* \fIx\fR,unsigned int \fIlen\fR, |
||||
const char* \fIcharset\fR,unsigned int \fIsetlen\fR); |
||||
.SH DESCRIPTION |
||||
Normally buffer_get_token copies data to \fIx\fR[0], \fIx\fR[1], ..., |
||||
\fIx\fR[\fIlen\fR-1] from the beginning of a string stored in |
||||
preallocated space; removes these \fIlen\fR bytes from the string; and |
||||
returns \fIlen\fR. |
||||
|
||||
If, however, the string has fewer than \fIlen\fR (but more than 0) |
||||
bytes, buffer_get_token copies only that many bytes, and returns that number. |
||||
|
||||
If the string is empty, buffer_get_token first uses a \fBread operation\fR to |
||||
feed data into the string. The \fBread operation\fR may indicate end of |
||||
input, in which case buffer_get_token returns 0; or a read error, in which |
||||
case buffer_get_token returns -1, setting \fIerrno\fR approporiately. |
||||
|
||||
The preallocated space and the \fBread operation\fR are specified by |
||||
\fIb\fR. You must initialize \fBb\fR using buffer_init before calling |
||||
buffer_get_token (or use the pre-initialized buffer_0). |
||||
.SH "SEE ALSO" |
||||
buffer_init(3), buffer_feed(3), buffer_peek(3), buffer_seek(3), buffer(3) |
@ -0,0 +1,11 @@
|
||||
.TH buffer_getc 3 |
||||
.SH NAME |
||||
buffer_getc \- read one char from buffer |
||||
.SH SYNTAX |
||||
.B #include <buffer.h> |
||||
|
||||
int \fBbuffer_getc\fP(buffer* \fIb\fR,char* \fIx\fR); |
||||
.SH DESCRIPTION |
||||
buffer_getc(b,x) is similar to buffer_get(b,x,1). |
||||
.SH "SEE ALSO" |
||||
buffer_init(3), buffer_get(3), buffer(3) |
@ -0,0 +1,22 @@
|
||||
.TH buffer_getn 3 |
||||
.SH NAME |
||||
buffer_getn \- read binary data from buffer |
||||
.SH SYNTAX |
||||
.B #include <buffer.h> |
||||
|
||||
int \fBbuffer_getn\fP(buffer* \fIb\fR,char* \fIx\fR,unsigned int \fIlen\fR); |
||||
.SH DESCRIPTION |
||||
buffer_getn copies data to \fIx\fR[0], \fIx\fR[1], ..., |
||||
\fIx\fR[\fIlen\fR-1] from the buffer, calling buffer_feed as needed, and |
||||
returns \fIlen\fR. |
||||
|
||||
If a read error occurs, buffer_getn returns -1 and sets \fIerrno\fR |
||||
appropriately. It may then have put any number between 0 and \fIlen\fR |
||||
in the buffer, you can't tell. That makes this function only useful if |
||||
you don't care when an error occurs. Use buffer_get otherwise. |
||||
|
||||
If the read operation signals end-of-file before \fIlen\fR bytes were |
||||
read, buffer_getn returns the number of bytes read from the buffer |
||||
before end-of-file. |
||||
.SH "SEE ALSO" |
||||
buffer_init(3), buffer_get(3), buffer(3) |
@ -0,0 +1,45 @@
|
||||
.TH buffer_init 3 |
||||
.SH NAME |
||||
buffer_init \- initialize buffer structure |
||||
.SH SYNTAX |
||||
.B #include <buffer.h> |
||||
|
||||
int \fBbuffer_init\fR(buffer &\fIb\fR, |
||||
int (*\fIop\fR)(int,char*,unsigned int), |
||||
int \fIfd\fR, char* \fIy\fR, unsigned int \fIylen\fR); |
||||
.SH DESCRIPTION |
||||
buffer_init prepares \fIb\fR to store a string in \fIy\fR[0], \fIy\fR[1], ..., |
||||
\fIy\fR[\fIylen\fR-1]. Initially the string is empty. |
||||
|
||||
buffer_init also prepares \fIb\fR to use the read/write operation specified by |
||||
\fIop\fR and \fIfd\fR. |
||||
|
||||
You can use |
||||
|
||||
buffer \fIb\fR = BUFFER_INIT(\fIop\fR,\fIfd\fR,\fIy\fR,\fIylen\fR); |
||||
|
||||
to initialize \fIb\fR statically if \fIop\fR, \fIfd\fR, \fIy\fR, and \fIylen\fR |
||||
are compile-time constants. |
||||
|
||||
You can call buffer_init again at any time. Note that this discards the |
||||
currently buffered string. |
||||
.SH EXAMPLE |
||||
#include <buffer.h> |
||||
#include <open.h> |
||||
|
||||
char buf[4096]; |
||||
int fd=open_read("/etc/services"); |
||||
buffer input; |
||||
|
||||
if (fd>=0) { |
||||
char x; |
||||
buffer_init(&input,read,fd,buf,sizeof buf); |
||||
while (buffer_get(&input,&x,1)==1) { |
||||
buffer_put(buffer_1,&x,1); |
||||
if (x=='\\n') break; |
||||
} |
||||
buffer_flush(buffer_1); |
||||
} |
||||
|
||||
.SH "SEE ALSO" |
||||
buffer_flush(3), buffer(3) |
@ -0,0 +1,23 @@
|
||||
.TH buffer_peek 3 |
||||
.SH NAME |
||||
buffer_peek \- return pointer to string in buffer |
||||
.SH SYNTAX |
||||
.B #include <buffer.h> |
||||
|
||||
int \fBbuffer_peek\fP(buffer* \fIb\fR); |
||||
.SH DESCRIPTION |
||||
buffer_peek returns a pointer to the first byte of the string in the |
||||
buffer. |
||||
.SH EXAMPLE |
||||
buffer_feed, buffer_peek and buffer_seek can be used for efficient reading |
||||
loops, nearly the same speed as calling \fBop\fR directly: |
||||
|
||||
for (;;) { |
||||
r = buffer_feed(&b); |
||||
if (r <= 0) return r; |
||||
x = buffer_peek(&b); |
||||
dosomething(x,r); |
||||
buffer_seek(&b,r); |
||||
} |
||||
.SH "SEE ALSO" |
||||
buffer_init(3), buffer_feed(3), buffer_get(3), buffer_seek(3), buffer(3) |
@ -0,0 +1,19 @@
|
||||
.TH buffer_put 3 |
||||
.SH NAME |
||||
buffer_put \- write binary data to buffer |
||||
.SH SYNTAX |
||||
.B #include <buffer.h> |
||||
|
||||
int \fBbuffer_put\fP(buffer* \fIb\fR,const char* \fIx\fR,unsigned int \fIlen\fR); |
||||
.SH DESCRIPTION |
||||
buffer_put writes \fIlen\fR bytes from \fIx\fR to \fIb\fR. |
||||
|
||||
The difference to buffer_putalign is that, when there isn't enough space |
||||
for new data, buffer_put calls buffer_flush before copying any data, |
||||
while buffer_putalign fills all available space with data before calling |
||||
buffer_flush. |
||||
|
||||
On success, buffer_put returns 0. On error, buffer_put returns -1, |
||||
setting \fIerrno\fR appropriately. |
||||
.SH "SEE ALSO" |
||||
buffer_putalign(3), buffer_puts(3), buffer_flush(3), buffer(3) |
@ -0,0 +1,13 @@
|
||||
.TH buffer_put8long 3 |
||||
.SH NAME |
||||
buffer_put8long \- write an octal ASCII representation of an unsigned |
||||
long integer to buffer |
||||
.SH SYNTAX |
||||
.B #include <buffer.h> |
||||
|
||||
int \fBbuffer_put8long\fP(buffer* \fIb\fR,unsigned long \fIx\fR); |
||||
.SH DESCRIPTION |
||||
buffer_put8long is similar to passing the result of fmt_8long to |
||||
buffer_put. |
||||
.SH "SEE ALSO" |
||||
fmt_8long(3), buffer_put(3), buffer_flush(3), buffer(3) |
@ -0,0 +1,16 @@
|
||||
.TH buffer_putalign 3 |
||||
.SH NAME |
||||
buffer_putalign \- write binary data to buffer |
||||
.SH SYNTAX |
||||
.B #include <buffer.h> |
||||
|
||||
int \fBbuffer_putalign\fP(buffer* \fIb\fR,const char* \fIx\fR,unsigned int \fIlen\fR); |
||||
.SH DESCRIPTION |
||||
buffer_putalign is similar to buffer_put. |
||||
|
||||
The difference to buffer_put is that, when there isn't enough space for |
||||
new data, buffer_put calls buffer_flush before copying any data, while |
||||
buffer_putalign fills all available space with data before calling |
||||
buffer_flush. |
||||
.SH "SEE ALSO" |
||||
buffer_put(3), buffer_putsalign(3), buffer_flush(3), buffer(3) |
@ -0,0 +1,13 @@
|
||||
.TH buffer_putflush 3 |
||||
.SH NAME |
||||
buffer_putflush \- write binary data to buffer and flush |
||||
.SH SYNTAX |
||||
.B #include <buffer.h> |
||||
|
||||
int \fBbuffer_putflush\fP(buffer* \fIb\fR, |
||||
const char* \fIx\fR,unsigned int \fIlen\fR); |
||||
.SH DESCRIPTION |
||||
buffer_putflush is similar to calling |
||||
buffer_put(\fIb\fR,\fIx\fR,\fIlen\fR) and then buffer_flush(\fIb\fR). |
||||
.SH "SEE ALSO" |
||||
buffer_put(3), buffer_flush(3), buffer(3) |
@ -0,0 +1,13 @@
|
||||
.TH buffer_putlong 3 |
||||
.SH NAME |
||||
buffer_putlong \- write a decimal ASCII representation of a signed |
||||
long integer to buffer |
||||
.SH SYNTAX |
||||
.B #include <buffer.h> |
||||
|
||||
int \fBbuffer_putlong\fP(buffer* \fIb\fR,unsigned long \fIx\fR); |
||||
.SH DESCRIPTION |
||||
buffer_putlong is similar to passing the result of fmt_long to |
||||
buffer_put. |
||||
.SH "SEE ALSO" |
||||
fmt_long(3), buffer_put(3), buffer_flush(3), buffer(3) |
@ -0,0 +1,12 @@
|
||||
.TH buffer_putnlflush 3 |
||||
.SH NAME |
||||
buffer_putnlflush \- write '\\n' to buffer and flush |
||||
.SH SYNTAX |
||||
.B #include <buffer.h> |
||||
|
||||
int \fBbuffer_putnlflush\fP(buffer* \fIb\fR); |
||||
.SH DESCRIPTION |
||||
buffer_putnlflush writes a single ASCII new-line character ('\\n') to |
||||
\fIb\fR and calls buffer_flush(\fIb\fR). |
||||
.SH "SEE ALSO" |
||||
buffer_puts(3), buffer_put(3), buffer_flush(3), buffer(3) |
@ -0,0 +1,17 @@
|
||||
.TH buffer_puts 3 |
||||
.SH NAME |
||||
buffer_puts \- write ASCIIZ string to buffer |
||||
.SH SYNTAX |
||||
.B #include <buffer.h> |
||||
|
||||
int \fBbuffer_puts\fP(buffer* \fIb\fR,const char* \fIx\fR); |
||||
.SH DESCRIPTION |
||||
buffer_puts is like buffer_put with \fIlen\fR determined as the number |
||||
of bytes before the first \\0 in \fIx\fR. |
||||
|
||||
The difference to buffer_putsalign is that, when there isn't enough space |
||||
for new data, buffer_puts calls buffer_flush before copying any data, |
||||
while buffer_putsalign fills all available space with data before calling |
||||
buffer_flush. |
||||
.SH "SEE ALSO" |
||||
buffer_putsalign(3), buffer_put(3), buffer_flush(3), buffer(3) |
@ -0,0 +1,12 @@
|
||||
.TH buffer_putsalign 3 |
||||
.SH NAME |
||||
buffer_putsalign \- write ASCIIZ string to buffer |
||||
.SH SYNTAX |
||||
.B #include <buffer.h> |
||||
|
||||
int \fBbuffer_putsalign\fP(buffer* \fIb\fR,const char* \fIx\fR); |
||||
.SH DESCRIPTION |
||||
buffer_putsalign is like buffer_putalign with \fIlen\fR determined as |
||||
the number of bytes before the first \\0 in \fIx\fR. |
||||
.SH "SEE ALSO" |
||||
buffer_puts(3), buffer_put(3), buffer_flush(3), buffer(3) |
@ -0,0 +1,12 @@
|
||||
.TH buffer_putsflush 3 |
||||
.SH NAME |
||||
buffer_putsflush \- write ASCIIZ string to buffer and flush |
||||
.SH SYNTAX |
||||
.B #include <buffer.h> |
||||
|
||||
int \fBbuffer_putsflush\fP(buffer* \fIb\fR,const char* \fIx\fR); |
||||
.SH DESCRIPTION |
||||
buffer_putsflush is like buffer_putflush with \fIlen\fR determined as |
||||
the number of bytes before the first \\0 in \fIx\fR. |
||||
.SH "SEE ALSO" |
||||
buffer_put(3), buffer_flush(3), buffer(3) |
@ -0,0 +1,11 @@
|
||||
.TH buffer_putspace 3 |
||||
.SH NAME |
||||
buffer_putspace \- write ASCII space to buffer |
||||
.SH SYNTAX |
||||
.B #include <buffer.h> |
||||
|
||||
int \fBbuffer_putspace\fP(buffer* \fIb\fR); |
||||
.SH DESCRIPTION |
||||
buffer_putspace writes a single ASCII space character to \fIb\fR. |
||||
.SH "SEE ALSO" |
||||
buffer_puts(3), buffer_put(3), buffer_flush(3), buffer(3) |
@ -0,0 +1,13 @@
|
||||
.TH buffer_putulong 3 |
||||
.SH NAME |
||||
buffer_putulong \- write a decimal ASCII representation of an unsigned |
||||
long integer to buffer |
||||
.SH SYNTAX |
||||
.B #include <buffer.h> |
||||
|
||||
int \fBbuffer_putulong\fP(buffer* \fIb\fR,unsigned long \fIx\fR); |
||||
.SH DESCRIPTION |
||||
buffer_putulong is similar to passing the result of fmt_ulong to |
||||
buffer_put. |
||||
.SH "SEE ALSO" |
||||
fmt_ulong(3), buffer_put(3), buffer_flush(3), buffer(3) |
@ -0,0 +1,13 @@
|
||||
.TH buffer_putxlong 3 |
||||
.SH NAME |
||||
buffer_putxlong \- write a hexidecimal ASCII representation of an unsigned |
||||
long integer to buffer |
||||
.SH SYNTAX |
||||
.B #include <buffer.h> |
||||
|
||||
int \fBbuffer_putxlong\fP(buffer* \fIb\fR,unsigned long \fIx\fR); |
||||
.SH DESCRIPTION |
||||
buffer_putxlong is similar to passing the result of fmt_xlong to |
||||
buffer_put. |
||||
.SH "SEE ALSO" |
||||
fmt_xlong(3), buffer_put(3), buffer_flush(3), buffer(3) |
@ -0,0 +1,12 @@
|
||||
.TH buffer_seek 3 |
||||
.SH NAME |
||||
buffer_seek \- remove bytes from beginning of string in buffer |
||||
.SH SYNTAX |
||||
.B #include <buffer.h> |
||||
|
||||
int \fBbuffer_seek\fP(buffer* \fIb\fR,unsigned int \fIr\fR); |
||||
.SH DESCRIPTION |
||||
buffer_seek removes \fIr\fR bytes from the beginning of the string. |
||||
\fIr\fR must be at most the current length of the string. |
||||
.SH "SEE ALSO" |
||||
buffer_init(3), buffer_feed(3), buffer_peek(3), buffer_get(3), buffer(3) |
@ -0,0 +1,7 @@
|
||||
#include "buffer.h" |
||||
|
||||
void buffer_seek(buffer* b,unsigned int len) { |
||||
unsigned int n=b->p+len; |
||||
if (n>b->n) n=b->n; |
||||
b->p=n; |
||||
} |
@ -0,0 +1,13 @@
|
||||
.TH scan_8short 3 |
||||
.SH NAME |
||||
scan_8short \- parse an unsigned short integer in octal ASCII representation |
||||
.SH SYNTAX |
||||
.B #include <scan.h> |
||||
|
||||
int \fBscan_8short\fP(const char *\fIsrc\fR,unsigned short *\fIdest\fR); |
||||
.SH DESCRIPTION |
||||
scan_8short parses an unsigned short integer in octal ASCII representation |
||||
from \fIsrc\fR and writes the result into \fIdest\fR. It returns the |
||||
number of bytes read from \fIsrc\fR. |
||||
.SH "SEE ALSO" |
||||
scan_xshort(3) |
@ -0,0 +1,13 @@
|
||||
.TH scan_ushort 3 |
||||
.SH NAME |
||||
scan_ushort \- parse an unsigned short integer in decimal ASCII representation |
||||
.SH SYNTAX |
||||
.B #include <scan.h> |
||||
|
||||
int \fBscan_ushort\fP(const char *\fIsrc\fR,unsigned short *\fIdest\fR); |
||||
.SH DESCRIPTION |
||||
scan_ushort parses an unsigned short integer in decimal ASCII representation |
||||
from \fIsrc\fR and writes the result into \fIdest\fR. It returns the |
||||
number of bytes read from \fIsrc\fR. |
||||
.SH "SEE ALSO" |
||||
scan_xshort(3), scan_8short(3), fmt_ulong(3) |
@ -0,0 +1,17 @@
|
||||
.TH scan_xshort 3 |
||||
.SH NAME |
||||
scan_xshort \- parse an unsigned short integer in hexadecimal ASCII representation |
||||
.SH SYNTAX |
||||
.B #include <scan.h> |
||||
|
||||
int \fBscan_xshort\fP(const char *\fIsrc\fR,unsigned short *\fIdest\fR); |
||||
.SH DESCRIPTION |
||||
scan_xshort parses an unsigned short integer in hexadecimal ASCII |
||||
representation from \fIsrc\fR and writes the result into \fIdest\fR. It |
||||
returns the number of bytes read from \fIsrc\fR. |
||||
|
||||
scan_xshort understands both upper and lower case letters. |
||||
|
||||
scan_xshort does not expect or understand a "0x" prefix. |
||||
.SH "SEE ALSO" |
||||
fmt_xshort(3) |
Loading…
Reference in new issue