From cc754bc6e3be0f37ca0eaca4b6b90f033433fb1a Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Mon, 29 Oct 2007 01:00:52 -0500 Subject: libalpm: introduce MALLOC and CALLOC macros These macros take the place of the common 4 or 5 line blocks of code we had in most places that called malloc or calloc. This should reduce some code duplication and make memory allocation more standard in libalpm. Highlights: * Note that the MALLOC macro actually uses calloc, this is just for safety so that memory is initialized to 0. This can be easily changed in one place. * One malloc call was completely eliminated- it made more sense to do it on the stack. * The use of RET_ERR in public functions (mainly the alpm_*_new functions) was standardized, this makes sense so pm_errno is set. Signed-off-by: Dan McGee --- lib/libalpm/conflict.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'lib/libalpm/conflict.c') diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c index d09c996d..0baef8d1 100644 --- a/lib/libalpm/conflict.c +++ b/lib/libalpm/conflict.c @@ -239,12 +239,9 @@ static alpm_list_t *add_fileconflict(alpm_list_t *conflicts, pmconflicttype_t type, const char *filestr, const char* name1, const char* name2) { - pmconflict_t *conflict = malloc(sizeof(pmconflict_t)); - if(conflict == NULL) { - _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes\n"), - sizeof(pmconflict_t)); - return(conflicts); - } + pmconflict_t *conflict; + MALLOC(conflict, sizeof(pmconflict_t), return(conflicts)); + conflict->type = type; strncpy(conflict->target, name1, PKG_NAME_LEN); strncpy(conflict->file, filestr, CONFLICT_FILE_LEN); -- cgit v1.2.3-54-g00ecf