Introduce xbps_xasprintf() and use it where required.

--HG--
extra : convert_revision : 324a92a4824476059e0993d00c2b925c732a79f8
This commit is contained in:
Juan RP
2009-04-04 19:32:39 +02:00
parent f5dd58df5d
commit 4bf5c5f750
14 changed files with 108 additions and 175 deletions

View File

@@ -128,7 +128,7 @@ main(int argc, char **argv)
prop_array_t reqby, orphans;
prop_object_t obj;
prop_object_iterator_t iter;
const char *pkgname, *version, *sep;
const char *pkgname, *version, *sep, *rootdir;
char *plist;
int c, flags = 0, rv = 0;
bool chkhash = false, forcerm = false, verbose = false;
@@ -169,7 +169,9 @@ main(int argc, char **argv)
if (argc != 1)
usage();
plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB);
rootdir = xbps_get_rootdir();
plist = xbps_xasprintf("%s/%s/%s", rootdir,
XBPS_META_PATH, XBPS_REGPKGDB);
if (plist == NULL)
exit(EXIT_FAILURE);

View File

@@ -114,7 +114,7 @@ main(int argc, char **argv)
if (argc < 1)
usage();
plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB);
plist = xbps_xasprintf("%s/%s/%s", root, XBPS_META_PATH, XBPS_REGPKGDB);
if (plist == NULL) {
printf("=> ERROR: couldn't find regpkdb file (%s)\n",
strerror(errno));

View File

@@ -262,7 +262,7 @@ xbps_repo_genindex(const char *pkgdir)
(strcmp(archdirs[i], "noarch")))
continue;
path = xbps_append_full_path(false, pkgdir, archdirs[i]);
path = xbps_xasprintf("%s/%s", pkgdir, archdirs[i]);
if (path == NULL)
return errno;
@@ -282,8 +282,7 @@ xbps_repo_genindex(const char *pkgdir)
continue;
foundpkg = true;
binfile = xbps_append_full_path(false, path,
dp->d_name);
binfile = xbps_xasprintf("%s/%s", path, dp->d_name);
if (binfile == NULL) {
(void)closedir(dirp);
free(path);

View File

@@ -181,24 +181,15 @@ int
show_pkg_info_from_metadir(const char *pkgname)
{
prop_dictionary_t pkgd;
size_t len = 0;
char *plist, *path;
const char *rootdir;
char *plist;
/* XBPS_META_PATH/metadata/<pkgname> + NULL */
len = strlen(XBPS_META_PATH) + strlen(pkgname) + 12;
path = malloc(len);
if (path == NULL)
rootdir = xbps_get_rootdir();
plist = xbps_xasprintf("%s/%s/metadata/%s/%s", rootdir,
XBPS_META_PATH, pkgname, XBPS_PKGPROPS);
if (plist == NULL)
return EINVAL;
(void)snprintf(path, len, "%s/metadata/%s", XBPS_META_PATH, pkgname);
plist = xbps_append_full_path(true, path, XBPS_PKGPROPS);
if (plist == NULL) {
free(path);
return EINVAL;
}
free(path);
pkgd = prop_dictionary_internalize_from_file(plist);
if (pkgd == NULL) {
free(plist);
@@ -217,27 +208,15 @@ show_pkg_files_from_metadir(const char *pkgname, bool hash)
{
prop_dictionary_t pkgd;
struct show_files_cb sfc;
size_t len = 0;
const char *destdir = xbps_get_rootdir();
char *plist, *path;
char *plist;
int rv = 0;
/* XBPS_META_PATH/metadata/<pkgname>/XBPS_PKGFILES + NULL */
len = strlen(XBPS_META_PATH) + strlen(pkgname) +
strlen(XBPS_PKGFILES) + 12;
path = malloc(len);
if (path == NULL)
plist = xbps_xasprintf("%s/%s/metadata/%s/%s", destdir,
XBPS_META_PATH, pkgname, XBPS_PKGFILES);
if (plist == NULL)
return EINVAL;
(void)snprintf(path, len, "%s/metadata/%s", XBPS_META_PATH, pkgname);
plist = xbps_append_full_path(true, path, XBPS_PKGFILES);
if (plist == NULL) {
free(path);
return EINVAL;
}
free(path);
pkgd = prop_dictionary_internalize_from_file(plist);
if (pkgd == NULL) {
free(plist);
@@ -277,7 +256,7 @@ show_pkg_files(prop_object_t obj, void *arg, bool *loop_done)
if (sfc->check_hash && file != NULL) {
printf("%s", file);
if (sfc->destdir) {
path = xbps_append_full_path(false, sfc->destdir, file);
path = xbps_xasprintf("%s/%s", sfc->destdir, file);
if (path == NULL)
return EINVAL;
}