Commit b469a1a1 authored by David Woodhouse's avatar David Woodhouse

Add buf_append_bytes() function

Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent 84112740
......@@ -92,6 +92,30 @@ void __attribute__ ((format (printf, 2, 3)))
}
}
void buf_append_bytes(struct oc_text_buf *buf, const void *bytes, int len)
{
int new_buf_len;
if (!buf || buf->error)
return;
new_buf_len = (buf->pos + len + BUF_CHUNK_SIZE - 1) & ~(BUF_CHUNK_SIZE-1);
if (new_buf_len > MAX_BUF_LEN) {
buf->error = -E2BIG;
return;
}
if (buf->buf_len < new_buf_len) {
realloc_inplace(buf->data, new_buf_len);
if (!buf->data) {
buf->error =- -ENOMEM;
return;
}
buf->buf_len = new_buf_len;
}
memcpy(buf->data + buf->pos, bytes, len);
buf->pos += len;
}
int buf_error(struct oc_text_buf *buf)
{
return buf ? buf->error : -ENOMEM;
......
......@@ -568,6 +568,7 @@ int prepare_stoken(struct openconnect_info *vpninfo);
struct oc_text_buf *buf_alloc(void);
void __attribute__ ((format (printf, 2, 3)))
buf_append(struct oc_text_buf *buf, const char *fmt, ...);
void buf_append_bytes(struct oc_text_buf *buf, const void *bytes, int len);
int buf_error(struct oc_text_buf *buf);
int buf_free(struct oc_text_buf *buf);
char *openconnect_create_useragent(const char *base);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment