diff options
author | David Sommerseth <dazo@users.sourceforge.net> | 2009-09-07 21:10:22 +0200 |
---|---|---|
committer | David Sommerseth <dazo@users.sourceforge.net> | 2009-09-07 21:10:22 +0200 |
commit | 66b29488a7ed5909564ed03b3e89cd0d008df09e (patch) | |
tree | 2ef1558a3c54b37b59a775f4734cb467cac183cb /common/eurephia_nullsafe.h | |
parent | 428d4fd45100c5c9b799f2fb127775b8b2382ecc (diff) | |
download | eurephia-66b29488a7ed5909564ed03b3e89cd0d008df09e.tar.gz eurephia-66b29488a7ed5909564ed03b3e89cd0d008df09e.tar.xz eurephia-66b29488a7ed5909564ed03b3e89cd0d008df09e.zip |
Moved all malloc() operations over to a calloc wrapper, malloc_nullsafe()
This also improves debugging as well, if debug logging is enabled and log level is >= 40.
Diffstat (limited to 'common/eurephia_nullsafe.h')
-rw-r--r-- | common/eurephia_nullsafe.h | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/common/eurephia_nullsafe.h b/common/eurephia_nullsafe.h index 55a9148..fde8c2f 100644 --- a/common/eurephia_nullsafe.h +++ b/common/eurephia_nullsafe.h @@ -3,7 +3,7 @@ * standard C string functions, which is made NULL safe by checking * if input value is NULL before performing the action. * - * GPLv2 only - Copyright (C) 2008 + * GPLv2 only - Copyright (C) 2008, 2009 * David Sommerseth <dazo@users.sourceforge.net> * * This program is free software; you can redistribute it and/or @@ -32,6 +32,8 @@ * */ +#include <eurephia_context.h> + #ifndef EUREPHIA_NULLSAFE_H_ #define EUREPHIA_NULLSAFE_H_ @@ -66,6 +68,21 @@ #define strlen_nullsafe(str) (str != NULL ? strlen(str) : 0) + +void *__malloc_nullsafe(eurephiaCTX *, size_t, const char *, int); + +/** + * calloc() wrapper. Should replace the use of malloc() and memset(). This + * function uses calloc internally, which results in the memory region being zero'd + * by the kernel on allocation. + * + * @param ctx eurephiaCTX (used for debugg logging) + * @param size Size of the memory region wanted + * + * @return Returns a pointer to the memory region on success, otherwise NULL. + */ +#define malloc_nullsafe(ctx, sz) __malloc_nullsafe(ctx, sz, __FILE__, __LINE__) + /** * free() wrapper. Frees memory allocated by malloc() or calloc(). It also sets the * input pointer to NULL on success. |