Skip to content

Commit

Permalink
Add k5_buf_get_space
Browse files Browse the repository at this point in the history
Add a new k5_buf method to make room in the buffer for the caller to
fill in.
  • Loading branch information
greghudson committed May 17, 2014
1 parent ba15586 commit ccd989b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/include/k5-buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ void k5_buf_add_fmt(struct k5buf *buf, const char *fmt, ...)
#endif
;

/* Extend the length of buf by len and return a pointer to the reserved space,
* to be filled in by the caller. Return NULL on error. */
void *k5_buf_get_space(struct k5buf *buf, size_t len);

/* Truncate BUF. LEN must be between 0 and the existing buffer
* length, or an assertion failure will result. */
void k5_buf_truncate(struct k5buf *buf, size_t len);
Expand Down
10 changes: 10 additions & 0 deletions src/util/support/k5buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ k5_buf_add_fmt(struct k5buf *buf, const char *fmt, ...)
free(tmp);
}

void *
k5_buf_get_space(struct k5buf *buf, size_t len)
{
if (!ensure_space(buf, len))
return NULL;
buf->len += len;
buf->data[buf->len] = '\0';
return &buf->data[buf->len - len];
}

void
k5_buf_truncate(struct k5buf *buf, size_t len)
{
Expand Down
1 change: 1 addition & 0 deletions src/util/support/libkrb5support-fixed.exports
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ k5_buf_init_dynamic
k5_buf_add
k5_buf_add_len
k5_buf_add_fmt
k5_buf_get_space
k5_buf_truncate
k5_buf_data
k5_buf_len
Expand Down

0 comments on commit ccd989b

Please sign in to comment.