krb5 commit: Add k5_buf_get_space

Greg Hudson ghudson at MIT.EDU
Sat May 17 19:54:28 EDT 2014


https://github.com/krb5/krb5/commit/ccd989bdc2656b153bc226462e0c13800810ae04
commit ccd989bdc2656b153bc226462e0c13800810ae04
Author: Greg Hudson <ghudson at mit.edu>
Date:   Sun May 4 15:43:35 2014 -0400

    Add k5_buf_get_space
    
    Add a new k5_buf method to make room in the buffer for the caller to
    fill in.

 src/include/k5-buf.h                          |    4 ++++
 src/util/support/k5buf.c                      |   10 ++++++++++
 src/util/support/libkrb5support-fixed.exports |    1 +
 3 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/src/include/k5-buf.h b/src/include/k5-buf.h
index c5576a3..da10fd9 100644
--- a/src/include/k5-buf.h
+++ b/src/include/k5-buf.h
@@ -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);
diff --git a/src/util/support/k5buf.c b/src/util/support/k5buf.c
index 778e68b..c3c81b0 100644
--- a/src/util/support/k5buf.c
+++ b/src/util/support/k5buf.c
@@ -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)
 {
diff --git a/src/util/support/libkrb5support-fixed.exports b/src/util/support/libkrb5support-fixed.exports
index 2f38242..f5fbe9e 100644
--- a/src/util/support/libkrb5support-fixed.exports
+++ b/src/util/support/libkrb5support-fixed.exports
@@ -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


More information about the cvs-krb5 mailing list