From 7905cd6a2eddbf264242bb2a85f811878b2da7ab Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Sat, 9 Feb 2013 00:43:35 -0500 Subject: 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. --- src/include/k5-int.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/include') 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, -- cgit