summaryrefslogtreecommitdiff
path: root/lib/libalpm/deps.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2007-10-29 01:00:52 -0500
committerDan McGee <dan@archlinux.org>2007-10-29 01:00:52 -0500
commitcc754bc6e3be0f37ca0eaca4b6b90f033433fb1a (patch)
treea9940053625e4b4e9b5d345eb1ac441a911f6efa /lib/libalpm/deps.c
parentfe3a461703a5d90937c0c6f1ce0c3d802c0f8630 (diff)
downloadpacman-cc754bc6e3be0f37ca0eaca4b6b90f033433fb1a.tar.xz
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 <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/deps.c')
-rw-r--r--lib/libalpm/deps.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index b459ca6c..f399083c 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -71,11 +71,7 @@ pmdepmissing_t *_alpm_depmiss_new(const char *target, pmdeptype_t type,
ALPM_LOG_FUNC;
- miss = malloc(sizeof(pmdepmissing_t));
- if(miss == NULL) {
- _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes\n"), sizeof(pmdepmissing_t));
- RET_ERR(PM_ERR_MEMORY, NULL);
- }
+ MALLOC(miss, sizeof(pmdepmissing_t), RET_ERR(PM_ERR_MEMORY, NULL));
strncpy(miss->target, target, PKG_NAME_LEN);
miss->type = type;
@@ -524,11 +520,7 @@ pmdepend_t SYMEXPORT *alpm_splitdep(const char *depstring)
}
newstr = strdup(depstring);
- depend = malloc(sizeof(pmdepend_t));
- if(depend == NULL) {
- _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes\n"), sizeof(pmdepend_t));
- return(NULL);
- }
+ MALLOC(depend, sizeof(pmdepend_t), return(NULL));
/* Find a version comparator if one exists. If it does, set the type and
* increment the ptr accordingly so we can copy the right strings. */
@@ -855,12 +847,11 @@ char SYMEXPORT *alpm_dep_get_string(pmdepend_t *dep)
ASSERT(handle != NULL, return(NULL));
ASSERT(dep != NULL, return(NULL));
+ /* TODO redo the sprintf, change to snprintf and
+ * make it less hacky and dependent on sizeof, etc */
char *ptr;
- char *depstring = malloc(sizeof(pmdepend_t));
- if(depstring == NULL) {
- _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes\n"), sizeof(pmdepend_t));
- return NULL;
- }
+ char *depstring;
+ MALLOC(depstring, sizeof(pmdepend_t), RET_ERR(PM_ERR_MEMORY, NULL));
strcpy(depstring, dep->name);
ptr = depstring + strlen(depstring);