Improve binpkg priorities, dynamically allocate mem, etc.

--HG--
extra : convert_revision : 479011aba6e9da4e5662137381e04042e762d428
This commit is contained in:
Juan RP 2008-12-27 22:19:04 +01:00
parent 86cdb7dae6
commit 926b1dfa4a
7 changed files with 167 additions and 68 deletions

View File

@ -46,6 +46,8 @@ static prop_dictionary_t getrepolist_dict(const char *);
static bool pkgindex_getinfo(prop_dictionary_t, repo_info_t *);
static void usage(void);
static char *plist;
static void
usage(void)
{
@ -106,17 +108,18 @@ static prop_dictionary_t
getrepolist_dict(const char *root)
{
prop_dictionary_t dict;
char plist[PATH_MAX];
xbps_set_rootdir(root);
if (!xbps_append_full_path(true, plist, NULL, XBPS_REPOLIST))
plist = xbps_append_full_path(true, NULL, XBPS_REPOLIST);
if (plist == NULL)
exit(1);
dict = prop_dictionary_internalize_from_file(plist);
if (dict == NULL) {
printf("ERROR: cannot find repository plist file (%s).\n",
strerror(errno));
free(plist);
exit(EINVAL);
}
@ -170,16 +173,14 @@ main(int argc, char **argv)
{
prop_dictionary_t dict;
repo_info_t *rinfo = NULL;
char dpkgidx[PATH_MAX], repolist[PATH_MAX], *root = NULL;
char dpkgidx[PATH_MAX], *root = NULL;
int c, rv = 0;
while ((c = getopt(argc, argv, "r:")) != -1) {
switch (c) {
case 'r':
/* To specify the root directory */
root = strdup(optarg);
if (root == NULL)
exit(ENOMEM);
root = optarg;
xbps_set_rootdir(root);
break;
case '?':
@ -203,27 +204,30 @@ main(int argc, char **argv)
exit(EINVAL);
/* Temp buffer to verify pkgindex file. */
if (!xbps_append_full_path(false, repolist, dpkgidx,
XBPS_PKGINDEX))
plist = xbps_append_full_path(false, dpkgidx, XBPS_PKGINDEX);
if (plist == NULL)
exit(EINVAL);
dict = prop_dictionary_internalize_from_file(repolist);
dict = prop_dictionary_internalize_from_file(plist);
if (dict == NULL) {
printf("Directory %s does not contain any "
"xbps pkgindex file.\n", dpkgidx);
free(plist);
exit(EINVAL);
}
rinfo = malloc(sizeof(*rinfo));
if (rinfo == NULL) {
prop_object_release(dict);
free(plist);
exit(ENOMEM);
}
if (!pkgindex_getinfo(dict, rinfo)) {
printf("'%s' is incomplete.\n", repolist);
printf("'%s' is incomplete.\n", plist);
prop_object_release(dict);
free(rinfo);
free(plist);
exit(EINVAL);
}
@ -232,6 +236,7 @@ main(int argc, char **argv)
strerror(errno));
prop_object_release(dict);
free(rinfo);
free(plist);
exit(EINVAL);
}
@ -241,6 +246,7 @@ main(int argc, char **argv)
prop_object_release(dict);
free(rinfo);
free(plist);
} else if (strcasecmp(argv[0], "repo-list") == 0) {
/* Lists all repositories registered in pool. */
@ -251,6 +257,7 @@ main(int argc, char **argv)
(void)xbps_callback_array_iter_in_dict(dict,
"repository-list", xbps_list_strings_in_array, NULL);
prop_object_release(dict);
free(plist);
} else if (strcasecmp(argv[0], "repo-rm") == 0) {
/* Remove a repository from the pool. */
@ -279,6 +286,7 @@ main(int argc, char **argv)
(void)xbps_callback_array_iter_in_dict(dict,
"repository-list", xbps_search_string_in_pkgs, argv[1]);
prop_object_release(dict);
free(plist);
} else if (strcasecmp(argv[0], "show") == 0) {
/* Shows info about a binary package. */
@ -289,32 +297,38 @@ main(int argc, char **argv)
if (xbps_callback_array_iter_in_dict(dict, "repository-list",
xbps_show_pkg_info_from_repolist, argv[1]) != 0) {
prop_object_release(dict);
free(plist);
printf("ERROR: unable to locate package '%s'.\n",
argv[1]);
exit(EINVAL);
}
prop_object_release(dict);
free(plist);
} else if (strcasecmp(argv[0], "list") == 0) {
/* Lists packages currently registered in database. */
if (argc != 1)
usage();
if (!xbps_append_full_path(true, dpkgidx, NULL, XBPS_REGPKGDB))
plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB);
if (plist == NULL)
exit(EINVAL);
dict = prop_dictionary_internalize_from_file(dpkgidx);
dict = prop_dictionary_internalize_from_file(plist);
if (dict == NULL) {
printf("No packages currently registered.\n");
free(plist);
exit(0);
}
if (!xbps_callback_array_iter_in_dict(dict, "packages",
xbps_list_pkgs_in_dict, NULL)) {
prop_object_release(dict);
free(plist);
exit(EINVAL);
}
prop_object_release(dict);
free(plist);
} else if (strcasecmp(argv[0], "install") == 0) {
/* Installs a binary package and required deps. */

View File

@ -72,7 +72,7 @@ main(int argc, char **argv)
{
prop_dictionary_t dbdict = NULL, pkgdict;
const char *version;
char dbfile[PATH_MAX], *in_chroot_env, *root = NULL;
char *dbfile, *in_chroot_env, *root = NULL;
bool in_chroot = false;
int c, rv = 0;
@ -97,7 +97,8 @@ main(int argc, char **argv)
if (argc < 1)
usage();
if (!xbps_append_full_path(true, dbfile, NULL, XBPS_REGPKGDB)) {
dbfile = xbps_append_full_path(true, NULL, XBPS_REGPKGDB);
if (dbfile == NULL) {
printf("=> ERROR: couldn't find regpkdb file (%s)\n",
strerror(errno));
exit(EINVAL);

View File

@ -153,7 +153,7 @@ int xbps_search_string_in_pkgs(prop_object_t, void *, bool *);
/* Utils */
void xbps_set_rootdir(const char *);
bool xbps_append_full_path(bool, char *, const char *, const char *);
char * xbps_append_full_path(bool, const char *, const char *);
int xbps_check_is_installed_pkg(const char *);
int xbps_cmpver_packages(const char *, const char *);
int xbps_cmpver_versions(const char *, const char *);

View File

@ -49,12 +49,13 @@ xbps_check_is_installed_pkg(const char *pkg)
prop_dictionary_t dict, pkgdict;
prop_object_t obj;
const char *reqver, *instver;
char plist[PATH_MAX], *pkgname;
char *plist, *pkgname;
int rv = 0;
assert(pkg != NULL);
if (!xbps_append_full_path(true, plist, NULL, XBPS_REGPKGDB))
plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB);
if (plist == NULL)
return EINVAL;
pkgname = xbps_get_pkg_name(pkg);
@ -64,6 +65,7 @@ xbps_check_is_installed_pkg(const char *pkg)
dict = prop_dictionary_internalize_from_file(plist);
if (dict == NULL) {
free(pkgname);
free(plist);
return 1; /* not installed */
}
@ -71,6 +73,7 @@ xbps_check_is_installed_pkg(const char *pkg)
if (pkgdict == NULL) {
prop_object_release(dict);
free(pkgname);
free(plist);
return 1; /* not installed */
}
@ -85,6 +88,7 @@ xbps_check_is_installed_pkg(const char *pkg)
rv = xbps_cmpver_versions(instver, reqver) > 0 ? 1 : 0;
free(pkgname);
free(plist);
prop_object_release(dict);
return rv;
@ -137,9 +141,10 @@ xbps_add_pkg_dependency(const char *pkg, uint64_t prio, prop_dictionary_t repo)
free(pkgname);
dep->repo = prop_dictionary_copy(repo);
dep->namever = pkg;
dep->priority = 0;
if (SIMPLEQ_EMPTY(&pkg_deps_queue)) {
SIMPLEQ_INSERT_HEAD(&pkg_deps_queue, dep, deps);
SIMPLEQ_INSERT_TAIL(&pkg_deps_queue, dep, deps);
return;
}
@ -149,9 +154,9 @@ xbps_add_pkg_dependency(const char *pkg, uint64_t prio, prop_dictionary_t repo)
*/
dep_prev = SIMPLEQ_FIRST(&pkg_deps_queue);
if (prio > dep_prev->priority)
SIMPLEQ_INSERT_TAIL(&pkg_deps_queue, dep, deps);
else
SIMPLEQ_INSERT_HEAD(&pkg_deps_queue, dep, deps);
else
SIMPLEQ_INSERT_TAIL(&pkg_deps_queue, dep, deps);
}
static int
@ -195,9 +200,13 @@ find_deps_in_pkg(prop_dictionary_t repo, prop_dictionary_t pkg)
* Package is on repo, add it into the list.
*/
prio_num = prop_dictionary_get(pkgdict, "priority");
if (prio_num == NULL)
prio = 0;
if (prio_num == NULL ||
prop_number_unsigned_integer_value(prio_num) == 0) {
if (xbps_pkg_has_rundeps(pkgdict))
prio = 10;
else
prio = 20;
} else
prio = prop_number_unsigned_integer_value(prio_num);
xbps_add_pkg_dependency(reqpkg, prio, repo);
@ -226,24 +235,29 @@ xbps_install_pkg_deps(prop_dictionary_t pkg)
struct pkg_dependency *dep;
size_t required_deps = 0, deps_found = 0;
const char *reqpkg, *version, *pkgname, *desc;
char plist[PATH_MAX], *namestr;
char *plist, *namestr;
int rv = 0;
bool dep_found = false;
assert(pkg != NULL);
if (!xbps_append_full_path(true, plist, NULL, XBPS_REPOLIST))
plist = xbps_append_full_path(true, NULL, XBPS_REPOLIST);
if (plist == NULL)
return EINVAL;
repolistd = prop_dictionary_internalize_from_file(plist);
if (repolistd == NULL)
if (repolistd == NULL) {
free(plist);
return EINVAL;
}
free(plist);
array = prop_dictionary_get(repolistd, "repository-list");
assert(array != NULL);
iter = prop_array_iterator(array);
if (iter == NULL) {
free(plist);
prop_object_release(repolistd);
return ENOMEM;
}
@ -253,9 +267,9 @@ xbps_install_pkg_deps(prop_dictionary_t pkg)
* all required dependencies.
*/
while ((obj = prop_object_iterator_next(iter)) != NULL) {
memset(plist, 0, sizeof(&plist));
if (!xbps_append_full_path(false, plist,
prop_string_cstring_nocopy(obj), XBPS_PKGINDEX)) {
plist = xbps_append_full_path(false,
prop_string_cstring_nocopy(obj), XBPS_PKGINDEX);
if (plist == NULL) {
xbps_clean_pkg_depslist();
prop_object_iterator_release(iter);
rv = EINVAL;
@ -264,11 +278,13 @@ xbps_install_pkg_deps(prop_dictionary_t pkg)
repod = prop_dictionary_internalize_from_file(plist);
if (repod == NULL) {
free(plist);
prop_object_iterator_release(iter);
rv = errno;
goto out;
}
free(plist);
rv = find_deps_in_pkg(repod, pkg);
if (rv == -1) {
prop_object_release(repod);

View File

@ -38,26 +38,29 @@ xbps_install_binary_pkg_from_repolist(prop_object_t obj, void *arg,
{
prop_dictionary_t repod, pkgrd;
const char *pkgname = arg, *version, *desc;
char plist[PATH_MAX];
char *plist;
int rv = 0;
/*
* Get the dictionary from a repository's index file.
*/
memset(plist, 0, sizeof(&plist));
if (!xbps_append_full_path(false, plist,
prop_string_cstring_nocopy(obj), XBPS_PKGINDEX))
plist = xbps_append_full_path(false,
prop_string_cstring_nocopy(obj), XBPS_PKGINDEX);
if (plist == NULL)
return EINVAL;
repod = prop_dictionary_internalize_from_file(plist);
if (repod == NULL)
if (repod == NULL) {
free(plist);
return EINVAL;
}
/*
* Get the package dictionary from current repository.
*/
pkgrd = xbps_find_pkg_in_dict(repod, pkgname);
if (pkgrd == NULL) {
free(plist);
prop_object_release(repod);
return XBPS_PKG_ENOTINREPO;
}
@ -79,6 +82,7 @@ xbps_install_binary_pkg_from_repolist(prop_object_t obj, void *arg,
if (rv == EEXIST)
rv = 0;
}
free(plist);
prop_object_release(repod);
*loop_done = true;
return rv;
@ -89,6 +93,7 @@ xbps_install_binary_pkg_from_repolist(prop_object_t obj, void *arg,
*/
rv = xbps_install_pkg_deps(pkgrd);
if (rv != 0) {
free(plist);
prop_object_release(repod);
return rv;
}
@ -102,6 +107,7 @@ xbps_install_binary_pkg_from_repolist(prop_object_t obj, void *arg,
if (rv == EEXIST)
rv = 0;
}
free(plist);
prop_object_release(repod);
*loop_done = true;
@ -112,7 +118,7 @@ int
xbps_install_binary_pkg(const char *pkgname, const char *destdir)
{
prop_dictionary_t repolistd;
char plist[PATH_MAX];
char *plist;
int rv = 0;
assert(pkgname != NULL);
@ -125,12 +131,15 @@ xbps_install_binary_pkg(const char *pkgname, const char *destdir)
* Get the dictionary with the list of registered
* repositories.
*/
if (!xbps_append_full_path(true, plist, NULL, XBPS_REPOLIST))
plist = xbps_append_full_path(true, NULL, XBPS_REPOLIST);
if (plist == NULL)
return EINVAL;
repolistd = prop_dictionary_internalize_from_file(plist);
if (repolistd == NULL)
if (repolistd == NULL) {
free(plist);
return EINVAL;
}
/*
* Iterate over the repositories to find the binary packages
@ -138,6 +147,8 @@ xbps_install_binary_pkg(const char *pkgname, const char *destdir)
*/
rv = xbps_callback_array_iter_in_dict(repolistd, "repository-list",
xbps_install_binary_pkg_from_repolist, (void *)pkgname);
free(plist);
prop_object_release(repolistd);
return rv;
@ -163,25 +174,29 @@ xbps_register_pkg(const char *pkgname, const char *version, const char *desc)
{
prop_dictionary_t dict, pkgd;
prop_array_t array;
char plist[PATH_MAX];
char *plist;
int rv = 0;
assert(pkgname != NULL);
assert(version != NULL);
assert(desc != NULL);
if (!xbps_append_full_path(true, plist, NULL, XBPS_REGPKGDB))
plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB);
if (plist == NULL)
return EINVAL;
dict = prop_dictionary_internalize_from_file(plist);
if (dict == NULL) {
/* No packages registered yet. */
dict = prop_dictionary_create();
if (dict == NULL)
if (dict == NULL) {
free(plist);
return ENOMEM;
}
array = prop_array_create();
if (array == NULL) {
free(plist);
prop_object_release(dict);
return ENOMEM;
}
@ -192,12 +207,14 @@ xbps_register_pkg(const char *pkgname, const char *version, const char *desc)
prop_object_release(array);
prop_object_release(dict);
prop_object_release(pkgd);
free(plist);
return EINVAL;
}
if (!xbps_add_obj_to_dict(dict, array, "packages")) {
prop_object_release(array);
prop_object_release(dict);
free(plist);
return EINVAL;
}
@ -206,6 +223,7 @@ xbps_register_pkg(const char *pkgname, const char *version, const char *desc)
pkgd = xbps_find_pkg_in_dict(dict, pkgname);
if (pkgd != NULL) {
prop_object_release(dict);
free(plist);
return EEXIST;
}
@ -216,6 +234,7 @@ xbps_register_pkg(const char *pkgname, const char *version, const char *desc)
if (!xbps_add_obj_to_array(array, pkgd)) {
prop_object_release(pkgd);
prop_object_release(dict);
free(plist);
return EINVAL;
}
}
@ -225,6 +244,7 @@ xbps_register_pkg(const char *pkgname, const char *version, const char *desc)
rv = errno;
prop_object_release(dict);
free(plist);
return rv;
}
@ -253,6 +273,7 @@ xbps_unpack_archive_cb(struct archive *ar)
if ((rv = archive_read_extract(ar, entry, flags)) != 0) {
printf("\ncouldn't unpack %s (%s), exiting!\n",
archive_entry_pathname(entry), strerror(errno));
archive_entry_free(entry);
break;
}
}
@ -267,7 +288,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg,
{
prop_string_t pkgname, version, filename, repoloc;
struct archive *ar;
char binfile[PATH_MAX];
char *binfile;
int rv;
assert(pkg != NULL);
@ -278,9 +299,10 @@ xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg,
filename = prop_dictionary_get(pkg, "filename");
repoloc = prop_dictionary_get(repo, "location-local");
if (!xbps_append_full_path(false, binfile,
binfile= xbps_append_full_path(false,
prop_string_cstring_nocopy(repoloc),
prop_string_cstring_nocopy(filename)))
prop_string_cstring_nocopy(filename));
if (binfile == NULL)
return EINVAL;
pkgname = prop_dictionary_get(pkg, "pkgname");
@ -296,8 +318,10 @@ xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg,
(void)fflush(stdout);
ar = archive_read_new();
if (ar == NULL)
if (ar == NULL) {
free(binfile);
return ENOMEM;
}
/* Enable support for all format and compression methods */
archive_read_support_compression_all(ar);
@ -305,6 +329,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg,
if ((rv = archive_read_open_filename(ar, binfile, 2048)) != 0) {
archive_read_finish(ar);
free(binfile);
return rv;
}
@ -313,5 +338,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg,
(void)fflush(stdout);
}
free(binfile);
return rv;
}

View File

@ -270,11 +270,12 @@ xbps_register_repository(const char *uri)
prop_dictionary_t dict;
prop_array_t array = NULL;
prop_object_t obj;
char plist[PATH_MAX];
char *plist;
assert(uri != NULL);
if (!xbps_append_full_path(true, plist, NULL, XBPS_REPOLIST)) {
plist = xbps_append_full_path(true, NULL, XBPS_REPOLIST);
if (plist == NULL) {
errno = EINVAL;
return false;
}
@ -284,13 +285,16 @@ xbps_register_repository(const char *uri)
if (dict == NULL) {
/* Looks like not, create it. */
dict = prop_dictionary_create();
if (dict == NULL)
if (dict == NULL) {
free(plist);
return false;
}
/* Create the array and add the repository URI on it. */
array = prop_array_create();
if (array == NULL) {
prop_object_release(dict);
free(plist);
return false;
}
@ -306,6 +310,7 @@ xbps_register_repository(const char *uri)
goto fail;
prop_object_release(dict);
} else {
/* Append into the array, the plist file exists. */
array = prop_dictionary_get(dict, "repository-list");
@ -332,13 +337,17 @@ xbps_register_repository(const char *uri)
return false;
}
prop_object_release(obj);
prop_object_release(dict);
}
free(plist);
return true;
fail:
prop_object_release(dict);
free(plist);
return false;
}
@ -348,23 +357,27 @@ xbps_unregister_repository(const char *uri)
prop_dictionary_t dict;
prop_array_t array;
struct callback_args *cb;
char plist[PATH_MAX];
char *plist;
bool done = false;
assert(uri != NULL);
if (!xbps_append_full_path(true, plist, NULL, XBPS_REPOLIST)) {
plist = xbps_append_full_path(true, NULL, XBPS_REPOLIST);
if (plist == NULL) {
errno = EINVAL;
return false;
}
dict = prop_dictionary_internalize_from_file(plist);
if (dict == NULL)
if (dict == NULL) {
free(plist);
return false;
}
array = prop_dictionary_get(dict, "repository-list");
if (array == NULL) {
prop_object_release(dict);
free(plist);
return false;
}
@ -373,6 +386,7 @@ xbps_unregister_repository(const char *uri)
cb = malloc(sizeof(*cb));
if (cb == NULL) {
prop_object_release(dict);
free(plist);
errno = ENOMEM;
return false;
}
@ -390,6 +404,7 @@ xbps_unregister_repository(const char *uri)
if (prop_dictionary_externalize_to_file(dict, plist)) {
free(cb);
prop_object_release(dict);
free(plist);
return true;
}
} else {
@ -399,6 +414,8 @@ xbps_unregister_repository(const char *uri)
prop_object_release(dict);
free(cb);
free(plist);
return false;
}
@ -508,7 +525,7 @@ xbps_search_string_in_pkgs(prop_object_t obj, void *arg, bool *loop_done)
{
prop_dictionary_t dict;
const char *repofile;
char plist[PATH_MAX];
char *plist;
assert(prop_object_type(obj) == PROP_TYPE_STRING);
@ -516,17 +533,21 @@ xbps_search_string_in_pkgs(prop_object_t obj, void *arg, bool *loop_done)
repofile = prop_string_cstring_nocopy(obj);
assert(repofile != NULL);
if (!xbps_append_full_path(false, plist, repofile, XBPS_PKGINDEX))
plist = xbps_append_full_path(false, repofile, XBPS_PKGINDEX);
if (plist == NULL)
return EINVAL;
dict = prop_dictionary_internalize_from_file(plist);
if (dict == NULL)
if (dict == NULL) {
free(plist);
return EINVAL;
}
printf("From %s repository ...\n", repofile);
xbps_callback_array_iter_in_dict(dict, "packages",
xbps_show_pkg_namedesc, arg);
prop_object_release(dict);
free(plist);
return 0;
}
@ -537,7 +558,7 @@ xbps_show_pkg_info_from_repolist(prop_object_t obj, void *arg, bool *loop_done)
prop_dictionary_t dict, pkgdict;
prop_string_t oloc;
const char *repofile, *repoloc;
char plist[PATH_MAX];
char *plist;
assert(prop_object_type(obj) == PROP_TYPE_STRING);
@ -545,16 +566,20 @@ xbps_show_pkg_info_from_repolist(prop_object_t obj, void *arg, bool *loop_done)
repofile = prop_string_cstring_nocopy(obj);
/* Get string for pkg-index.plist with full path. */
if (!xbps_append_full_path(false, plist, repofile, XBPS_PKGINDEX))
plist = xbps_append_full_path(false, repofile, XBPS_PKGINDEX);
if (plist == NULL)
return EINVAL;
dict = prop_dictionary_internalize_from_file(plist);
if (dict == NULL || prop_dictionary_count(dict) == 0)
if (dict == NULL || prop_dictionary_count(dict) == 0) {
free(plist);
return EINVAL;
}
pkgdict = xbps_find_pkg_in_dict(dict, arg);
if (pkgdict == NULL) {
prop_object_release(dict);
free(plist);
return XBPS_PKG_ENOTINREPO;
}
@ -566,6 +591,7 @@ xbps_show_pkg_info_from_repolist(prop_object_t obj, void *arg, bool *loop_done)
repoloc = prop_string_cstring_nocopy(oloc);
else {
prop_object_release(dict);
free(plist);
return EINVAL;
}
@ -573,6 +599,7 @@ xbps_show_pkg_info_from_repolist(prop_object_t obj, void *arg, bool *loop_done)
xbps_show_pkg_info(pkgdict);
*loop_done = true;
prop_object_release(dict);
free(plist);
return 0;
}

View File

@ -88,14 +88,15 @@ xbps_set_rootdir(const char *dir)
rootdir = dir;
}
bool
xbps_append_full_path(bool use_rootdir, char *buf, const char *basedir,
const char *plistf)
char *
xbps_append_full_path(bool use_rootdir, const char *basedir, const char *plist)
{
const char *env;
char *buf;
size_t len = 0;
assert(buf != NULL);
assert(plistf != NULL);
assert(plist != NULL);
if (basedir)
env = basedir;
@ -103,18 +104,31 @@ xbps_append_full_path(bool use_rootdir, char *buf, const char *basedir,
env = XBPS_META_PATH;
if (rootdir && use_rootdir) {
if (snprintf(buf, PATH_MAX - 1, "%s/%s/%s",
rootdir, env, plistf) < 0) {
len = strlen(rootdir) + strlen(env) + strlen(plist) + 2;
buf = malloc(len + 1);
if (buf == NULL) {
errno = ENOMEM;
return NULL;
}
if (snprintf(buf, len + 1, "%s/%s/%s",
rootdir, env, plist) < 0) {
errno = ENOSPC;
return false;
return NULL;
}
} else {
if (snprintf(buf, PATH_MAX - 1, "%s/%s",
env, plistf) < 0) {
len = strlen(env) + strlen(plist) + 1;
buf = malloc(len + 1);
if (buf == NULL) {
errno = ENOMEM;
return NULL;
}
if (snprintf(buf, len + 1, "%s/%s", env, plist) < 0) {
errno = ENOSPC;
return false;
return NULL;
}
}
return true;
return buf;
}