Lines Matching defs:cbuf
33 circbuffer *cbuf = NULL;
36 dropbear_exit("bad cbuf size");
39 cbuf = (circbuffer*)m_malloc(sizeof(circbuffer));
40 cbuf->data = (unsigned char*)m_malloc(size);
41 cbuf->used = 0;
42 cbuf->readpos = 0;
43 cbuf->writepos = 0;
44 cbuf->size = size;
46 return cbuf;
49 void cbuf_free(circbuffer * cbuf) {
51 m_free(cbuf->data);
52 m_free(cbuf);
55 unsigned int cbuf_getused(circbuffer * cbuf) {
57 return cbuf->used;
61 unsigned int cbuf_getavail(circbuffer * cbuf) {
63 return cbuf->size - cbuf->used;
67 unsigned int cbuf_readlen(circbuffer *cbuf) {
69 dropbear_assert(((2*cbuf->size)+cbuf->writepos-cbuf->readpos)%cbuf->size == cbuf->used%cbuf->size);
70 dropbear_assert(((2*cbuf->size)+cbuf->readpos-cbuf->writepos)%cbuf->size == (cbuf->size-cbuf->used)%cbuf->size);
72 if (cbuf->used == 0) {
77 if (cbuf->readpos < cbuf->writepos) {
78 return cbuf->writepos - cbuf->readpos;
81 return cbuf->size - cbuf->readpos;
84 unsigned int cbuf_writelen(circbuffer *cbuf) {
86 dropbear_assert(cbuf->used <= cbuf->size);
87 dropbear_assert(((2*cbuf->size)+cbuf->writepos-cbuf->readpos)%cbuf->size == cbuf->used%cbuf->size);
88 dropbear_assert(((2*cbuf->size)+cbuf->readpos-cbuf->writepos)%cbuf->size == (cbuf->size-cbuf->used)%cbuf->size);
90 if (cbuf->used == cbuf->size) {
95 if (cbuf->writepos < cbuf->readpos) {
96 return cbuf->readpos - cbuf->writepos;
99 return cbuf->size - cbuf->writepos;
102 unsigned char* cbuf_readptr(circbuffer *cbuf, unsigned int len) {
103 if (len > cbuf_readlen(cbuf)) {
104 dropbear_exit("bad cbuf read");
107 return &cbuf->data[cbuf->readpos];
110 unsigned char* cbuf_writeptr(circbuffer *cbuf, unsigned int len) {
112 if (len > cbuf_writelen(cbuf)) {
113 dropbear_exit("bad cbuf write");
116 return &cbuf->data[cbuf->writepos];
119 void cbuf_incrwrite(circbuffer *cbuf, unsigned int len) {
120 if (len > cbuf_writelen(cbuf)) {
121 dropbear_exit("bad cbuf write");
124 cbuf->used += len;
125 dropbear_assert(cbuf->used <= cbuf->size);
126 cbuf->writepos = (cbuf->writepos + len) % cbuf->size;
130 void cbuf_incrread(circbuffer *cbuf, unsigned int len) {
131 if (len > cbuf_readlen(cbuf)) {
132 dropbear_exit("bad cbuf read");
135 dropbear_assert(cbuf->used >= len);
136 cbuf->used -= len;
137 cbuf->readpos = (cbuf->readpos + len) % cbuf->size;