Home | History | Annotate | Download | only in qemu

Lines Matching refs:cb

29 cbuffer_assert( CBuffer*  cb, const char*  file, long  lineno )
33 if (cb->rpos < 0 || cb->rpos >= cb->size) {
36 else if (cb->count < 0 || cb->count > cb->size) {
43 file, lineno, reason, cb->rpos, cb->count, cb->size);
46 # define CBUFFER_ASSERT(cb) cbuffer_assert(cb,__FUNCTION__,__LINE__)
48 # define CBUFFER_ASSERT(cb) ((void)0)
52 cbuffer_write_peek( CBuffer* cb, uint8_t* *pbase )
54 int wpos = cb->rpos + cb->count;
55 int avail = cb->size - cb->count;
57 CBUFFER_ASSERT(cb);
59 if (wpos >= cb->size)
60 wpos -= cb->size;
62 if (wpos + avail > cb->size)
63 avail = cb->size - wpos;
65 *pbase = cb->buff + wpos;
70 cbuffer_write_step( CBuffer* cb, int len )
72 CBUFFER_ASSERT(cb);
74 cb->count += len;
75 if (cb->count > cb->size)
76 cb->count = cb->size;
81 cbuffer_write( CBuffer* cb, const void* from, int len )
85 CBUFFER_ASSERT(cb);
88 int avail = cb->size - cb->count;
89 int wpos = cb->rpos + cb->count;
96 if (wpos >= cb->size)
97 wpos -= cb->size;
99 ASSERT( wpos >= 0 && wpos < cb->size, "wpos is out-of-bounds: %d (rpos=%d)", wpos, cb->rpos);
101 if (wpos + avail > cb->size)
102 avail = cb->size - wpos;
107 memcpy( cb->buff + wpos, (const char*)from, avail );
111 cb->count += avail;
117 cbuffer_read( CBuffer* cb, void* to, int len )
121 CBUFFER_ASSERT(cb);
124 int avail = cb->count;
125 int rpos = cb->rpos;
132 ASSERT((rpos >= 0 && rpos < cb->size), "rpos is out-of-bounds: %d", rpos);
134 if (rpos+avail > cb->size)
135 avail = cb->size - rpos;
140 memcpy( (char*)to, (const char*)cb->buff + rpos, avail );
143 cb->count -= avail;
144 cb->rpos += avail;
145 if (cb->rpos >= cb->size)
146 cb->rpos -= cb->size;
152 cbuffer_read_peek( CBuffer* cb, uint8_t* *pbase )
154 int rpos = cb->rpos;
155 int avail = cb->count;
157 CBUFFER_ASSERT(cb);
159 if (rpos + avail > cb->size)
160 avail = cb->size - rpos;
162 *pbase = cb->buff + rpos;
168 cbuffer_read_step( CBuffer* cb, int len )
170 CBUFFER_ASSERT(cb);
172 if (len > cb->count)
173 len = cb->count;
175 cb->rpos += len;
176 if (cb->rpos >= cb->size)
177 cb->rpos -= cb->size;
179 cb->count -= len;
183 cbuffer_quote( CBuffer* cb )
189 cb, cb->rpos, cb->count, cb->size );
198 cbuffer_quote_data( CBuffer* cb )
201 int len = cb->count;
202 int rpos = cb->rpos;
208 if (rpos >= cb->size)
209 rpos -= cb->size;
211 if (rpos + avail > cb->size)
212 avail = cb->size - rpos;
214 stralloc_add_quote_bytes( s, cb->buff + rpos, avail );
226 cbuffer_print( CBuffer* cb )
229 printf( "%s: %s", cbuffer_quote(cb), cbuffer_quote_data(cb) );