Skip to content

Commit

Permalink
Add buf_append_bytes() function
Browse files Browse the repository at this point in the history
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Jun 19, 2014
1 parent 8411274 commit b469a1a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions http.c
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions openconnect-internal.h
Expand Up @@ -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);
Expand Down

0 comments on commit b469a1a

Please sign in to comment.