blob: d25d765403cdd04b3a99f41aaa1ef80469c58780 [file] [log] [blame]
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001/* Copyright (C) 2007-2008 The Android Open Source Project
2**
3** This software is licensed under the terms of the GNU General Public
4** License version 2, as published by the Free Software Foundation, and
5** may be copied, distributed, and modified under those terms.
6**
7** This program is distributed in the hope that it will be useful,
8** but WITHOUT ANY WARRANTY; without even the implied warranty of
9** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10** GNU General Public License for more details.
11*/
12#ifndef _qemu_cbuffer_h
13#define _qemu_cbuffer_h
14
15#include <stdint.h>
16
17/* Basic circular buffer type and methods */
18
19typedef struct {
20 uint8_t* buff;
21 int size;
22 int rpos;
23 int count;
24} CBuffer;
25
26static __inline__ void
27cbuffer_reset( CBuffer* cb, void* buff, int size )
28{
29 cb->buff = buff;
30 cb->size = size;
31 cb->rpos = 0;
32 cb->count = 0;
33}
34
35static __inline__ int
36cbuffer_write_avail( CBuffer* cb )
37{
38 return cb->size - cb->count;
39}
40
41extern int cbuffer_write( CBuffer* cb, const void* from, int len );
42extern int cbuffer_write_peek( CBuffer* cb, uint8_t* *pbase );
43extern void cbuffer_write_step( CBuffer* cb, int len );
44
45static __inline__ int
46cbuffer_read_avail( CBuffer* cb )
47{
48 return cb->count;
49}
50
51extern int cbuffer_read( CBuffer* cb, void* to, int len );
52extern int cbuffer_read_peek( CBuffer* cb, uint8_t* *pbase );
53extern void cbuffer_read_step( CBuffer* cb, int len );
54
55extern const char* cbuffer_quote( CBuffer* cb );
56extern const char* cbuffer_quote_data( CBuffer* cb );
57extern void cbuffer_print( CBuffer* cb );
58
59#endif /* qemu_cbuffer_h */
60
61