diff options
author | Dan McGee <dan@archlinux.org> | 2007-10-29 01:00:52 -0500 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2007-10-29 01:00:52 -0500 |
commit | cc754bc6e3be0f37ca0eaca4b6b90f033433fb1a (patch) | |
tree | a9940053625e4b4e9b5d345eb1ac441a911f6efa /lib/libalpm/db.c | |
parent | fe3a461703a5d90937c0c6f1ce0c3d802c0f8630 (diff) | |
download | pacman-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/db.c')
-rw-r--r-- | lib/libalpm/db.c | 13 |
1 files changed, 2 insertions, 11 deletions
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index 1052840f..8c36c310 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -582,18 +582,9 @@ pmdb_t *_alpm_db_new(const char *dbpath, const char *treename) ALPM_LOG_FUNC; - db = calloc(1, sizeof(pmdb_t)); - if(db == NULL) { - _alpm_log(PM_LOG_ERROR, "calloc : %s\n", strerror(errno)); - RET_ERR(PM_ERR_MEMORY, NULL); - } + CALLOC(db, 1, sizeof(pmdb_t), RET_ERR(PM_ERR_MEMORY, NULL)); + CALLOC(db->path, 1, pathsize, RET_ERR(PM_ERR_MEMORY, NULL)); - db->path = calloc(1, pathsize); - if(db->path == NULL) { - _alpm_log(PM_LOG_ERROR, "calloc : %s\n", strerror(errno)); - FREE(db); - RET_ERR(PM_ERR_MEMORY, NULL); - } sprintf(db->path, "%s%s/", dbpath, treename); strncpy(db->treename, treename, PATH_MAX); |