1 #ifndef RH_BUFFER_H
 2 #define RH_BUFFER_H
 3 
 4 #include <stdlib.h>
 5 #include <sys/types.h>
 6 #include "rh_string.h"
 7 
 8 typedef struct rh_buffer rh_buffer_t;
 9 
10 #define RH_BUFFER_CONST 1
11 
12 struct rh_buffer {
13         char            *data;
14         size_t          used;
15         size_t          size;
16         uint            flags;
17         unsigned int    hash;
18 };
19 
20 #define FIXED_BUFFER(_name,_size)                       \
21         struct _name {                                  \
22                 char    data[_size];                    \
23                 size_t  used;                           \
24         }
25 
26 
27 #define rh_buffer_size(_b)      ((_b)->size - (_b)->used)
28 #define rh_buffer_ch_last(_b)   ((_b)->data[(_b)->used-1])
29 
30 #define RH_BUFFER_APPEND_BUFFER(_dst,_src)                      \
31         rh_buffer_append((_dst), (_src)->data, (_src)->used)
32 
33 #define RH_BUFFER_NUL(_buffer)                                  \
34         ( (_buffer)->data[(_buffer)->used] = 0 )
35 
36 
37 void rh_buffer_init (rh_buffer_t *);
38 void rh_buffer_destroy (rh_buffer_t *);
39 
40 int rh_buffer_reset (rh_buffer_t *buffer);
41 int rh_buffer_reserve (rh_buffer_t *, size_t);
42 
43 int rh_buffer_sprintf (rh_buffer_t *buffer, const char *fmt, ...);
44 
45 size_t rh_buffer_hashcase (rh_buffer_t *);
46 
47 int rh_buffer_append (rh_buffer_t *buffer, const void *src, size_t nsrc);
48 int rh_buffer_append_ch (rh_buffer_t *buffer, int ch, size_t count);
49 
50 int rh_buffer_append_encode_uri (rh_buffer_t *buffer,
51                                   const char *src, size_t count);
52 
53 void rh_buffer_set_const (rh_buffer_t *buffer, const void *src, size_t nsrc);
54 
55 #endif /* RH_BUFFER_H */


syntax highlighted by Code2HTML, v. 0.9.1