Home | History | Annotate | Download | only in qemu
      1 /* 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 
     19 typedef struct {
     20     uint8_t*  buff;
     21     int       size;
     22     int       rpos;
     23     int       count;
     24 } CBuffer;
     25 
     26 static __inline__ void
     27 cbuffer_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 
     35 static __inline__ int
     36 cbuffer_write_avail( CBuffer*  cb )
     37 {
     38     return cb->size - cb->count;
     39 }
     40 
     41 extern int  cbuffer_write( CBuffer*  cb, const void*  from, int  len );
     42 extern int  cbuffer_write_peek( CBuffer*  cb, uint8_t*  *pbase );
     43 extern void cbuffer_write_step( CBuffer*  cb, int  len );
     44 
     45 static __inline__ int
     46 cbuffer_read_avail( CBuffer*  cb )
     47 {
     48     return cb->count;
     49 }
     50 
     51 extern int  cbuffer_read( CBuffer*  cb, void*  to, int  len );
     52 extern int  cbuffer_read_peek( CBuffer*  cb, uint8_t*  *pbase );
     53 extern void cbuffer_read_step( CBuffer*  cb, int  len );
     54 
     55 extern const char*  cbuffer_quote( CBuffer*  cb );
     56 extern const char*  cbuffer_quote_data( CBuffer*  cb );
     57 extern void         cbuffer_print( CBuffer*  cb );
     58 
     59 #endif /* qemu_cbuffer_h */
     60 
     61 
     62