summaryrefslogtreecommitdiffstats
path: root/src/include
diff options
context:
space:
mode:
authorGreg Hudson <ghudson@mit.edu>2013-02-09 00:43:35 -0500
committerGreg Hudson <ghudson@mit.edu>2013-02-09 00:43:35 -0500
commit7905cd6a2eddbf264242bb2a85f811878b2da7ab (patch)
tree72b4028cbe0e399e1d293e2b718530913f0a2673 /src/include
parent92e2bac0f38f7f60a8fc74b5964357212c4289e1 (diff)
downloadkrb5-7905cd6a2eddbf264242bb2a85f811878b2da7ab.tar.gz
krb5-7905cd6a2eddbf264242bb2a85f811878b2da7ab.tar.xz
krb5-7905cd6a2eddbf264242bb2a85f811878b2da7ab.zip
Add and use k5memdup, k5memdup0 helpers
Add k5-int.h static functions to duplicate byte ranges, optionally with a trailing zero byte, and set an error code like k5alloc does. Use them where they would shorten existing code.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/k5-int.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/include/k5-int.h b/src/include/k5-int.h
index 9da1b63b6..9136bfc0e 100644
--- a/src/include/k5-int.h
+++ b/src/include/k5-int.h
@@ -2571,6 +2571,28 @@ k5alloc(size_t len, krb5_error_code *code)
return ptr;
}
+/* Return a copy of the len bytes of memory at in; set *code to 0 or ENOMEM. */
+static inline void *
+k5memdup(const void *in, size_t len, krb5_error_code *code)
+{
+ void *ptr = k5alloc(len, code);
+
+ if (ptr != NULL)
+ memcpy(ptr, in, len);
+ return ptr;
+}
+
+/* Like k5memdup, but add a final null byte. */
+static inline void *
+k5memdup0(const void *in, size_t len, krb5_error_code *code)
+{
+ void *ptr = k5alloc(len + 1, code);
+
+ if (ptr != NULL)
+ memcpy(ptr, in, len);
+ return ptr;
+}
+
krb5_error_code KRB5_CALLCONV
krb5_get_credentials_for_user(krb5_context context, krb5_flags options,
krb5_ccache ccache,