diff options
author | Greg Hudson <ghudson@mit.edu> | 2009-10-03 14:46:54 +0000 |
---|---|---|
committer | Greg Hudson <ghudson@mit.edu> | 2009-10-03 14:46:54 +0000 |
commit | 0faf98575f91452efee9f4c8d100c83fa9971e46 (patch) | |
tree | 3006933ddea34ae6b5a07da1a5909f33e1b67b43 | |
parent | 58703ca2fe8115ede0f38b327ca6cc60fcf3bb0d (diff) | |
download | krb5-0faf98575f91452efee9f4c8d100c83fa9971e46.tar.gz krb5-0faf98575f91452efee9f4c8d100c83fa9971e46.tar.xz krb5-0faf98575f91452efee9f4c8d100c83fa9971e46.zip |
Add convenience functions zapfree (test for null, zap, free) and
k5alloc (allocate memory, set a krb5_error_code result) to k5-int.h.
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@22838 dc483132-0cff-0310-8789-dd5450dbe970
-rw-r--r-- | src/include/k5-int.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/include/k5-int.h b/src/include/k5-int.h index 1cb2fdb925..1c8a1c92d8 100644 --- a/src/include/k5-int.h +++ b/src/include/k5-int.h @@ -776,6 +776,16 @@ static inline void krb5int_zap_data(void *ptr, size_t len) #endif /* WIN32 */ #define zap(p,l) krb5int_zap_data(p,l) +/* Convenience function: zap and free ptr if it is non-NULL. */ +static inline void +zapfree(void *ptr, size_t len) +{ + if (ptr != NULL) { + zap(ptr, len); + free(ptr); + } +} + /* A definition of init_state for DES based encryption systems. * sets up an 8-byte IV of all zeros */ @@ -2823,6 +2833,17 @@ static inline int authdata_eq (krb5_authdata a1, krb5_authdata a2) && !memcmp(a1.contents, a2.contents, a1.length)); } +/* Allocate zeroed memory; set *code to 0 on success or ENOMEM on failure. */ +static inline void * +k5alloc(size_t size, krb5_error_code *code) +{ + void *ptr; + + ptr = calloc(size, 1); + *code = (ptr == NULL) ? ENOMEM : 0; + return ptr; +} + krb5_error_code KRB5_CALLCONV krb5int_pac_sign(krb5_context context, krb5_pac pac, |