summaryrefslogtreecommitdiffhomepage
path: root/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/buffer.c b/buffer.c
index 579fa6f..13fa1ce 100644
--- a/buffer.c
+++ b/buffer.c
@@ -106,7 +106,7 @@ buffer* buf_newcopy(buffer* buf) {
/* Set the length of the buffer */
void buf_setlen(buffer* buf, unsigned int len) {
if (len > buf->size) {
- dropbear_exit("bad buf_setlen");
+ dropbear_exit("Bad buf_setlen");
}
buf->len = len;
}
@@ -114,7 +114,7 @@ void buf_setlen(buffer* buf, unsigned int len) {
/* Increment the length of the buffer */
void buf_incrlen(buffer* buf, unsigned int incr) {
if (incr > BUF_MAX_INCR || buf->len + incr > buf->size) {
- dropbear_exit("bad buf_incrlen");
+ dropbear_exit("Bad buf_incrlen");
}
buf->len += incr;
}
@@ -122,7 +122,7 @@ void buf_incrlen(buffer* buf, unsigned int incr) {
void buf_setpos(buffer* buf, unsigned int pos) {
if (pos > buf->len) {
- dropbear_exit("bad buf_setpos");
+ dropbear_exit("Bad buf_setpos");
}
buf->pos = pos;
}
@@ -130,7 +130,7 @@ void buf_setpos(buffer* buf, unsigned int pos) {
/* increment the postion by incr, increasing the buffer length if required */
void buf_incrwritepos(buffer* buf, unsigned int incr) {
if (incr > BUF_MAX_INCR || buf->pos + incr > buf->size) {
- dropbear_exit("bad buf_incrwritepos");
+ dropbear_exit("Bad buf_incrwritepos");
}
buf->pos += incr;
if (buf->pos > buf->len) {
@@ -144,7 +144,7 @@ void buf_incrpos(buffer* buf, int incr) {
if (incr > BUF_MAX_INCR ||
(unsigned int)((int)buf->pos + incr) > buf->len
|| ((int)buf->pos + incr) < 0) {
- dropbear_exit("bad buf_incrpos");
+ dropbear_exit("Bad buf_incrpos");
}
buf->pos += incr;
}
@@ -155,7 +155,7 @@ unsigned char buf_getbyte(buffer* buf) {
/* This check is really just ==, but the >= allows us to check for the
* bad case of pos > len, which should _never_ happen. */
if (buf->pos >= buf->len) {
- dropbear_exit("bad buf_getbyte");
+ dropbear_exit("Bad buf_getbyte");
}
return buf->data[buf->pos++];
}
@@ -185,7 +185,7 @@ void buf_putbyte(buffer* buf, unsigned char val) {
unsigned char* buf_getptr(buffer* buf, unsigned int len) {
if (buf->pos + len > buf->len) {
- dropbear_exit("bad buf_getptr");
+ dropbear_exit("Bad buf_getptr");
}
return &buf->data[buf->pos];
}
@@ -195,7 +195,7 @@ unsigned char* buf_getptr(buffer* buf, unsigned int len) {
unsigned char* buf_getwriteptr(buffer* buf, unsigned int len) {
if (buf->pos + len > buf->size) {
- dropbear_exit("bad buf_getwriteptr");
+ dropbear_exit("Bad buf_getwriteptr");
}
return &buf->data[buf->pos];
}
@@ -209,7 +209,7 @@ unsigned char* buf_getstring(buffer* buf, unsigned int *retlen) {
unsigned char* ret;
len = buf_getint(buf);
if (len > MAX_STRING_LEN) {
- dropbear_exit("string too long");
+ dropbear_exit("String too long");
}
if (retlen != NULL) {
@@ -223,6 +223,20 @@ unsigned char* buf_getstring(buffer* buf, unsigned int *retlen) {
return ret;
}
+/* Return a string as a newly allocated buffer */
+buffer * buf_getstringbuf(buffer *buf) {
+ buffer *ret;
+ unsigned char* str;
+ unsigned int len;
+ str = buf_getstring(buf, &len);
+ ret = m_malloc(sizeof(*ret));
+ ret->data = str;
+ ret->len = len;
+ ret->size = len;
+ ret->pos = 0;
+ return ret;
+}
+
/* Just increment the buffer position the same as if we'd used buf_getstring,
* but don't bother copying/malloc()ing for it */
void buf_eatstring(buffer *buf) {