comparison buffer.c @ 594:a98a2138364a

Improve capitalisation for all logged strings
author Matt Johnston <matt@ucc.asn.au>
date Wed, 23 Feb 2011 15:50:30 +0000
parents c3f2ec71e3d4
children 2b1bb792cd4d 9a5438271556 f336d232fc63
comparison
equal deleted inserted replaced
593:ea103e4476ce 594:a98a2138364a
104 } 104 }
105 105
106 /* Set the length of the buffer */ 106 /* Set the length of the buffer */
107 void buf_setlen(buffer* buf, unsigned int len) { 107 void buf_setlen(buffer* buf, unsigned int len) {
108 if (len > buf->size) { 108 if (len > buf->size) {
109 dropbear_exit("bad buf_setlen"); 109 dropbear_exit("Bad buf_setlen");
110 } 110 }
111 buf->len = len; 111 buf->len = len;
112 } 112 }
113 113
114 /* Increment the length of the buffer */ 114 /* Increment the length of the buffer */
115 void buf_incrlen(buffer* buf, unsigned int incr) { 115 void buf_incrlen(buffer* buf, unsigned int incr) {
116 if (incr > BUF_MAX_INCR || buf->len + incr > buf->size) { 116 if (incr > BUF_MAX_INCR || buf->len + incr > buf->size) {
117 dropbear_exit("bad buf_incrlen"); 117 dropbear_exit("Bad buf_incrlen");
118 } 118 }
119 buf->len += incr; 119 buf->len += incr;
120 } 120 }
121 /* Set the position of the buffer */ 121 /* Set the position of the buffer */
122 void buf_setpos(buffer* buf, unsigned int pos) { 122 void buf_setpos(buffer* buf, unsigned int pos) {
123 123
124 if (pos > buf->len) { 124 if (pos > buf->len) {
125 dropbear_exit("bad buf_setpos"); 125 dropbear_exit("Bad buf_setpos");
126 } 126 }
127 buf->pos = pos; 127 buf->pos = pos;
128 } 128 }
129 129
130 /* increment the postion by incr, increasing the buffer length if required */ 130 /* increment the postion by incr, increasing the buffer length if required */
131 void buf_incrwritepos(buffer* buf, unsigned int incr) { 131 void buf_incrwritepos(buffer* buf, unsigned int incr) {
132 if (incr > BUF_MAX_INCR || buf->pos + incr > buf->size) { 132 if (incr > BUF_MAX_INCR || buf->pos + incr > buf->size) {
133 dropbear_exit("bad buf_incrwritepos"); 133 dropbear_exit("Bad buf_incrwritepos");
134 } 134 }
135 buf->pos += incr; 135 buf->pos += incr;
136 if (buf->pos > buf->len) { 136 if (buf->pos > buf->len) {
137 buf->len = buf->pos; 137 buf->len = buf->pos;
138 } 138 }
142 * decrement the pos*/ 142 * decrement the pos*/
143 void buf_incrpos(buffer* buf, int incr) { 143 void buf_incrpos(buffer* buf, int incr) {
144 if (incr > BUF_MAX_INCR || 144 if (incr > BUF_MAX_INCR ||
145 (unsigned int)((int)buf->pos + incr) > buf->len 145 (unsigned int)((int)buf->pos + incr) > buf->len
146 || ((int)buf->pos + incr) < 0) { 146 || ((int)buf->pos + incr) < 0) {
147 dropbear_exit("bad buf_incrpos"); 147 dropbear_exit("Bad buf_incrpos");
148 } 148 }
149 buf->pos += incr; 149 buf->pos += incr;
150 } 150 }
151 151
152 /* Get a byte from the buffer and increment the pos */ 152 /* Get a byte from the buffer and increment the pos */
153 unsigned char buf_getbyte(buffer* buf) { 153 unsigned char buf_getbyte(buffer* buf) {
154 154
155 /* This check is really just ==, but the >= allows us to check for the 155 /* This check is really just ==, but the >= allows us to check for the
156 * bad case of pos > len, which should _never_ happen. */ 156 * bad case of pos > len, which should _never_ happen. */
157 if (buf->pos >= buf->len) { 157 if (buf->pos >= buf->len) {
158 dropbear_exit("bad buf_getbyte"); 158 dropbear_exit("Bad buf_getbyte");
159 } 159 }
160 return buf->data[buf->pos++]; 160 return buf->data[buf->pos++];
161 } 161 }
162 162
163 /* Get a bool from the buffer and increment the pos */ 163 /* Get a bool from the buffer and increment the pos */
183 /* returns an in-place pointer to the buffer, checking that 183 /* returns an in-place pointer to the buffer, checking that
184 * the next len bytes from that position can be used */ 184 * the next len bytes from that position can be used */
185 unsigned char* buf_getptr(buffer* buf, unsigned int len) { 185 unsigned char* buf_getptr(buffer* buf, unsigned int len) {
186 186
187 if (buf->pos + len > buf->len) { 187 if (buf->pos + len > buf->len) {
188 dropbear_exit("bad buf_getptr"); 188 dropbear_exit("Bad buf_getptr");
189 } 189 }
190 return &buf->data[buf->pos]; 190 return &buf->data[buf->pos];
191 } 191 }
192 192
193 /* like buf_getptr, but checks against total size, not used length. 193 /* like buf_getptr, but checks against total size, not used length.
194 * This allows writing past the used length, but not past the size */ 194 * This allows writing past the used length, but not past the size */
195 unsigned char* buf_getwriteptr(buffer* buf, unsigned int len) { 195 unsigned char* buf_getwriteptr(buffer* buf, unsigned int len) {
196 196
197 if (buf->pos + len > buf->size) { 197 if (buf->pos + len > buf->size) {
198 dropbear_exit("bad buf_getwriteptr"); 198 dropbear_exit("Bad buf_getwriteptr");
199 } 199 }
200 return &buf->data[buf->pos]; 200 return &buf->data[buf->pos];
201 } 201 }
202 202
203 /* Return a null-terminated string, it is malloced, so must be free()ed 203 /* Return a null-terminated string, it is malloced, so must be free()ed
207 207
208 unsigned int len; 208 unsigned int len;
209 unsigned char* ret; 209 unsigned char* ret;
210 len = buf_getint(buf); 210 len = buf_getint(buf);
211 if (len > MAX_STRING_LEN) { 211 if (len > MAX_STRING_LEN) {
212 dropbear_exit("string too long"); 212 dropbear_exit("String too long");
213 } 213 }
214 214
215 if (retlen != NULL) { 215 if (retlen != NULL) {
216 *retlen = len; 216 *retlen = len;
217 } 217 }