aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2007-04-18 17:43:08 +0000
committerMike Frysinger <vapier@gentoo.org>2007-04-18 17:43:08 +0000
commitdf92facd8c7908cb9fc77b46e5605238ac7373f1 (patch)
tree00ab19f0295f64114f40f29aaa2b68c92ba9bf81
parentcontinue gracefully if cache is out of sync with portdir (diff)
downloadportage-utils-df92facd8c7908cb9fc77b46e5605238ac7373f1.tar.gz
portage-utils-df92facd8c7908cb9fc77b46e5605238ac7373f1.tar.bz2
portage-utils-df92facd8c7908cb9fc77b46e5605238ac7373f1.zip
use xzalloc()
-rw-r--r--main.c8
-rw-r--r--qcache.c24
2 files changed, 12 insertions, 20 deletions
diff --git a/main.c b/main.c
index 09a2339b..15e077b1 100644
--- a/main.c
+++ b/main.c
@@ -1,7 +1,7 @@
/*
* Copyright 2005-2006 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/main.c,v 1.139 2007/04/10 22:00:51 solar Exp $
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/main.c,v 1.140 2007/04/18 17:43:08 vapier Exp $
*
* Copyright 2005-2006 Ned Ludd - <solar@gentoo.org>
* Copyright 2005-2006 Mike Frysinger - <vapier@gentoo.org>
@@ -281,8 +281,7 @@ static char *remove_extra_space(char *str)
if (str == NULL)
return NULL;
len = strlen(str);
- buf = xmalloc(len+1);
- memset(buf, 0, len+1);
+ buf = xzalloc(len+1);
for (p = str; *p != 0; ++p) {
if (!isspace(*p)) c = *p; else {
if (c == ' ') continue;
@@ -799,8 +798,7 @@ portage_cache *cache_read_file(const char *file)
if (fstat(fileno(f), &s) != 0)
goto err;
len = sizeof(*ret) + s.st_size + 1;
- ret = xmalloc(len);
- memset(ret, 0x00, len);
+ ret = xzalloc(len);
#if 0
{ /* This is the expected format of portage-2.0 cache code NAME=var */
/* at any time ferringb might decide to add new entries. CDEPEND= will be no more */
diff --git a/qcache.c b/qcache.c
index 61b360ad..a5934b8d 100644
--- a/qcache.c
+++ b/qcache.c
@@ -1,7 +1,7 @@
/*
* Copyright 2005-2006 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/qcache.c,v 1.25 2007/04/18 17:38:56 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/qcache.c,v 1.26 2007/04/18 17:43:08 vapier Exp $
*
* Copyright 2006 Thomas A. Cort - <tcort@gentoo.org>
*/
@@ -48,7 +48,7 @@ static const char *qcache_opts_help[] = {
COMMON_OPTS_HELP
};
-static const char qcache_rcsid[] = "$Id: qcache.c,v 1.25 2007/04/18 17:38:56 vapier Exp $";
+static const char qcache_rcsid[] = "$Id: qcache.c,v 1.26 2007/04/18 17:43:08 vapier Exp $";
#define qcache_usage(ret) usage(ret, QCACHE_FLAGS, qcache_long_opts, qcache_opts_help, lookup_applet_idx("qcache"))
/********************************************************************/
@@ -271,8 +271,7 @@ char **qcache_read_lines(char *filename)
return NULL;
len = sizeof(char*) * (num_lines + 1);
- lines = xmalloc(len);
- memset(lines, 0, len);
+ lines = xzalloc(len);
if ((fd = open(filename, O_RDONLY)) != -1) {
for (i = 0; i < num_lines; i++) {
@@ -283,8 +282,7 @@ char **qcache_read_lines(char *filename)
count++;
lseek(fd, (lseek(fd, 0, SEEK_CUR) - count - 1), SEEK_SET);
- lines[i] = xmalloc(sizeof(char) * (count+1));
- memset(lines[i], 0, count+1);
+ lines[i] = xzalloc(sizeof(char) * (count+1));
/* copy the line into lines[i] */
read(fd, lines[i], count);
@@ -549,8 +547,7 @@ int qcache_traverse(void (*func)(qcache_data*))
/* traverse packages */
for (j = 0; j < num_pkg; j++) {
len = sizeof(char) * (strlen(portdir) + strlen("/") + strlen(categories[i]->d_name) + strlen("/") + strlen(packages[j]->d_name) + 1);
- ebuildpath = xmalloc(len);
- memset(ebuildpath, 0, len);
+ ebuildpath = xzalloc(len);
snprintf(ebuildpath, len, "%s/%s/%s", portdir, categories[i]->d_name, packages[j]->d_name);
if (-1 == (num_ebuild = scandir(ebuildpath, &ebuilds, qcache_ebuild_select, qcache_vercmp))) {
@@ -576,8 +573,7 @@ int qcache_traverse(void (*func)(qcache_data*))
/* traverse ebuilds */
for (k = 0; k < num_ebuild; k++) {
len = sizeof(char) * (strlen(catpath) + strlen("/") + strlen(categories[i]->d_name) + strlen("/") + strlen(ebuilds[k]->d_name) + 1);
- cachepath = xmalloc(len);
- memset(cachepath, 0, len);
+ cachepath = xzalloc(len);
snprintf(cachepath, len, "%s/%s/%s", catpath, categories[i]->d_name, ebuilds[k]->d_name);
cachepath[len-8] = '\0'; /* remove ".ebuild" */
@@ -598,7 +594,7 @@ int qcache_traverse(void (*func)(qcache_data*))
qcache_free_data(data.cache_data);
} else
- warn("unable to read cache '%s'\n\tperhaps you need to `emerge --metadata` ?", cachepath);
+ warn("unable to read cache '%s'\n\tperhaps you need to `emerge --metadata` or `emerge --regen` ?", cachepath);
free(ebuilds[k]);
free(cachepath);
@@ -774,8 +770,7 @@ void qcache_stats(qcache_data *data)
architectures++;
len = sizeof(char) * (strlen(QCACHE_EDB) + strlen(portdir) + 1);
- catpath = xmalloc(len);
- memset(catpath, 0, len);
+ catpath = xzalloc(len);
snprintf(catpath, len, "%s%s", QCACHE_EDB, portdir);
if (-1 == (numcat = scandir(catpath, &categories, qcache_file_select, alphasort))) {
@@ -929,9 +924,8 @@ int qcache_init()
unsigned int len;
len = sizeof(char) * (strlen(portdir) + strlen("/profiles/arch.list") + 1);
- filename = xmalloc(len);
+ filename = xzalloc(len);
- memset(filename, 0, len);
snprintf(filename, len, "%s/profiles/arch.list", portdir);
if (NULL == (archlist = qcache_read_lines(filename))) {