fehQlibs 26
Qlibs
Loading...
Searching...
No Matches
buffer.h
Go to the documentation of this file.
1#ifndef BUFFER_H
2#define BUFFER_H
3#include <sys/types.h> /* need type: ssize_t */
4
5typedef struct buffer {
6 char *x;
7 unsigned int p;
8 size_t n;
9 int fd;
10 ssize_t (*op)();
12
13#define BUFFER_INIT(op,fd,buf,len) { (buf), 0, (len), (fd), (op) }
14#define BUFFER_SMALL 256
15#define BUFFER_INSIZE 8192
16#define BUFFER_OUTSIZE 8192
17#define BUFFER_MTUSIZE 1450
18
19extern void buffer_init(buffer *,ssize_t (*op)(),int,char *,size_t);
20
21extern int buffer_flush(buffer *);
22extern int buffer_put(buffer *,const char *,size_t);
23extern int buffer_putalign(buffer *,const char *,size_t);
24extern int buffer_putflush(buffer *,const char *,size_t);
25extern int buffer_puts(buffer *,const char *);
26extern int buffer_putsalign(buffer *,const char *);
27extern int buffer_putsflush(buffer *,const char *);
28
29#define buffer_PUTC(s,c) \
30 ( ((s)->n != (s)->p) \
31 ? ( (s)->x[(s)->p++] = (c), 0 ) \
32 : buffer_put((s),&(c),1) \
33 )
34
35extern int buffer_get(buffer *,char *,size_t);
36extern int buffer_bget(buffer *,char *,size_t);
37extern int buffer_feed(buffer *);
38
39extern char *buffer_peek(buffer *);
40extern void buffer_seek(buffer *,size_t);
41
42#define buffer_PEEK(s) ( (s)->x + (s)->n )
43#define buffer_SEEK(s,len) ( ( (s)->p -= (len) ) , ( (s)->n += (len) ) )
44
45#define buffer_GETC(s,c) \
46 ( ((s)->p > 0) \
47 ? ( *(c) = (s)->x[(s)->n], buffer_SEEK((s),1), 1 ) \
48 : buffer_get((s),(c),1) \
49 )
50
51extern int buffer_copy(buffer *,buffer *);
52
53extern ssize_t buffer_unixread(int,char *,size_t);
54extern ssize_t buffer_unixwrite(int,char *,size_t);
55
56extern buffer *buffer_0;
57extern buffer *buffer_1;
58extern buffer *buffer_2;
59extern buffer *buffer_0small;
60extern buffer *buffer_1small;
61extern buffer *buffer_2small;
62
63#endif
char * buffer_peek(buffer *)
Definition: buffer.c:132
int buffer_puts(buffer *, const char *)
Definition: buffer.c:218
buffer * buffer_1small
Definition: buffer.c:56
ssize_t buffer_unixread(int, char *, size_t)
Definition: buffer.c:28
int buffer_put(buffer *, const char *, size_t)
Definition: buffer.c:185
ssize_t buffer_unixwrite(int, char *, size_t)
Definition: buffer.c:33
buffer * buffer_1
Definition: buffer.c:44
int buffer_putflush(buffer *, const char *, size_t)
Definition: buffer.c:207
int buffer_putsflush(buffer *, const char *)
Definition: buffer.c:223
int buffer_get(buffer *, char *, size_t)
Definition: buffer.c:121
buffer * buffer_2small
Definition: buffer.c:60
void buffer_seek(buffer *, size_t)
Definition: buffer.c:137
buffer * buffer_2
Definition: buffer.c:48
buffer * buffer_0small
Definition: buffer.c:52
int buffer_bget(buffer *, char *, size_t)
Definition: buffer.c:110
int buffer_copy(buffer *, buffer *)
Definition: buffer.c:62
int buffer_feed(buffer *)
Definition: buffer.c:97
int buffer_putsalign(buffer *, const char *)
Definition: buffer.c:213
int buffer_putalign(buffer *, const char *, size_t)
Definition: buffer.c:171
int buffer_flush(buffer *)
Definition: buffer.c:161
void buffer_init(buffer *, ssize_t(*op)(), int, char *, size_t)
Definition: buffer.c:13
buffer * buffer_0
Definition: buffer.c:40
Definition: buffer.h:5
size_t n
Definition: buffer.h:8
int fd
Definition: buffer.h:9
unsigned int p
Definition: buffer.h:7
char * x
Definition: buffer.h:6
ssize_t(* op)()
Definition: buffer.h:10