Mercurial > hg > index.fcgi > gift-gnutella > gift-gnutella-0.0.11-1pba
comparison src/io/io_buf.h @ 0:d39e1d0d75b6
initial add
author | paulo@hit-nxdomain.opendns.com |
---|---|
date | Sat, 20 Feb 2010 21:18:28 -0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:b2b2ee36ade2 |
---|---|
1 /* | |
2 * $Id: io_buf.h,v 1.2 2003/09/17 17:44:11 hipnod Exp $ | |
3 * | |
4 * Copyright (C) 2003 giFT project (gift.sourceforge.net) | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify it | |
7 * under the terms of the GNU General Public License as published by the | |
8 * Free Software Foundation; either version 2, or (at your option) any | |
9 * later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, but | |
12 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * General Public License for more details. | |
15 */ | |
16 | |
17 #ifndef GIFT_GT_IO_BUF_H_ | |
18 #define GIFT_GT_IO_BUF_H_ | |
19 | |
20 /*****************************************************************************/ | |
21 | |
22 /* | |
23 * This duplicates libgift's String somewhat... | |
24 */ | |
25 struct io_buf | |
26 { | |
27 uint8_t *data; | |
28 size_t size; | |
29 size_t r_offs; | |
30 size_t w_offs; | |
31 }; | |
32 | |
33 /*****************************************************************************/ | |
34 | |
35 /* | |
36 * Macros for accessing particular things about an I/O buf... | |
37 */ | |
38 | |
39 #define io_buf_read_avail(io_buf) \ | |
40 ((io_buf)->w_offs - (io_buf)->r_offs) | |
41 | |
42 #define io_buf_len(io_buf) \ | |
43 ((io_buf)->w_offs) | |
44 | |
45 #define io_buf_size(io_buf) \ | |
46 ((io_buf)->size) | |
47 | |
48 #define io_buf_write_avail(io_buf) \ | |
49 ((io_buf)->size - (io_buf)->w_offs) | |
50 | |
51 #define io_buf_write_ptr(io_buf) \ | |
52 (&(io_buf)->data[(io_buf)->w_offs]) | |
53 | |
54 #define io_buf_read_ptr(iobuf) \ | |
55 (&(iobuf)->data[(iobuf)->r_offs]) | |
56 | |
57 /*****************************************************************************/ | |
58 | |
59 struct io_buf *io_buf_new (size_t len); | |
60 void io_buf_free (struct io_buf *buf); | |
61 uint8_t *io_buf_free_keep (struct io_buf *buf); | |
62 | |
63 BOOL io_buf_resize (struct io_buf *buf, size_t len); | |
64 void io_buf_reset (struct io_buf *buf); | |
65 | |
66 void io_buf_push (struct io_buf *buf, size_t len); | |
67 void io_buf_pop (struct io_buf *buf, size_t len); | |
68 | |
69 size_t io_buf_copy (struct io_buf *dst, struct io_buf *src, | |
70 size_t len); | |
71 | |
72 /*****************************************************************************/ | |
73 | |
74 #endif /* GIFT_GT_IO_BUF_H_ */ |