comparison circbuffer.c @ 241:c5d3ef11155f

* use own assertions which should get logged properly
author Matt Johnston <matt@ucc.asn.au>
date Mon, 05 Sep 2005 15:16:10 +0000
parents 0cfba3034be5
children a98a2138364a
comparison
equal deleted inserted replaced
238:e923801a7678 241:c5d3ef11155f
64 64
65 } 65 }
66 66
67 unsigned int cbuf_readlen(circbuffer *cbuf) { 67 unsigned int cbuf_readlen(circbuffer *cbuf) {
68 68
69 assert(((2*cbuf->size)+cbuf->writepos-cbuf->readpos)%cbuf->size == cbuf->used%cbuf->size); 69 dropbear_assert(((2*cbuf->size)+cbuf->writepos-cbuf->readpos)%cbuf->size == cbuf->used%cbuf->size);
70 assert(((2*cbuf->size)+cbuf->readpos-cbuf->writepos)%cbuf->size == (cbuf->size-cbuf->used)%cbuf->size); 70 dropbear_assert(((2*cbuf->size)+cbuf->readpos-cbuf->writepos)%cbuf->size == (cbuf->size-cbuf->used)%cbuf->size);
71 71
72 if (cbuf->used == 0) { 72 if (cbuf->used == 0) {
73 TRACE(("cbuf_readlen: unused buffer")) 73 TRACE(("cbuf_readlen: unused buffer"))
74 return 0; 74 return 0;
75 } 75 }
81 return cbuf->size - cbuf->readpos; 81 return cbuf->size - cbuf->readpos;
82 } 82 }
83 83
84 unsigned int cbuf_writelen(circbuffer *cbuf) { 84 unsigned int cbuf_writelen(circbuffer *cbuf) {
85 85
86 assert(cbuf->used <= cbuf->size); 86 dropbear_assert(cbuf->used <= cbuf->size);
87 assert(((2*cbuf->size)+cbuf->writepos-cbuf->readpos)%cbuf->size == cbuf->used%cbuf->size); 87 dropbear_assert(((2*cbuf->size)+cbuf->writepos-cbuf->readpos)%cbuf->size == cbuf->used%cbuf->size);
88 assert(((2*cbuf->size)+cbuf->readpos-cbuf->writepos)%cbuf->size == (cbuf->size-cbuf->used)%cbuf->size); 88 dropbear_assert(((2*cbuf->size)+cbuf->readpos-cbuf->writepos)%cbuf->size == (cbuf->size-cbuf->used)%cbuf->size);
89 89
90 if (cbuf->used == cbuf->size) { 90 if (cbuf->used == cbuf->size) {
91 TRACE(("cbuf_writelen: full buffer")) 91 TRACE(("cbuf_writelen: full buffer"))
92 return 0; /* full */ 92 return 0; /* full */
93 } 93 }
120 if (len > cbuf_writelen(cbuf)) { 120 if (len > cbuf_writelen(cbuf)) {
121 dropbear_exit("bad cbuf write"); 121 dropbear_exit("bad cbuf write");
122 } 122 }
123 123
124 cbuf->used += len; 124 cbuf->used += len;
125 assert(cbuf->used <= cbuf->size); 125 dropbear_assert(cbuf->used <= cbuf->size);
126 cbuf->writepos = (cbuf->writepos + len) % cbuf->size; 126 cbuf->writepos = (cbuf->writepos + len) % cbuf->size;
127 } 127 }
128 128
129 129
130 void cbuf_incrread(circbuffer *cbuf, unsigned int len) { 130 void cbuf_incrread(circbuffer *cbuf, unsigned int len) {
131 if (len > cbuf_readlen(cbuf)) { 131 if (len > cbuf_readlen(cbuf)) {
132 dropbear_exit("bad cbuf read"); 132 dropbear_exit("bad cbuf read");
133 } 133 }
134 134
135 assert(cbuf->used >= len); 135 dropbear_assert(cbuf->used >= len);
136 cbuf->used -= len; 136 cbuf->used -= len;
137 cbuf->readpos = (cbuf->readpos + len) % cbuf->size; 137 cbuf->readpos = (cbuf->readpos + len) % cbuf->size;
138 } 138 }