xbps-*: do not pass a NULL pointer to xbps_end().

This commit is contained in:
Juan RP
2011-07-29 11:27:43 +02:00
parent 2857214afa
commit 4aa06921ff
3 changed files with 56 additions and 53 deletions

View File

@ -58,9 +58,10 @@ write_plist_file(prop_dictionary_t dict, const char *file)
}
static void __attribute__((noreturn))
usage(void)
usage(struct xbps_handle *xhp)
{
xbps_end(xbps_handle_get());
if (xhp != NULL)
xbps_end(xhp);
fprintf(stderr,
"usage: xbps-uhelper [options] [action] [args]\n"
@ -134,7 +135,7 @@ main(int argc, char **argv)
exit(EXIT_SUCCESS);
case '?':
default:
usage();
usage(NULL);
}
}
@ -142,7 +143,7 @@ main(int argc, char **argv)
argv += optind;
if (argc < 1)
usage();
usage(NULL);
/*
* Initialize the callbacks and debug in libxbps.
@ -178,7 +179,7 @@ main(int argc, char **argv)
if (strcasecmp(argv[0], "register") == 0) {
/* Registers a package into the database */
if (argc != 4)
usage();
usage(xhp);
dict = prop_dictionary_create();
if (dict == NULL)
@ -218,7 +219,7 @@ main(int argc, char **argv)
} else if (strcasecmp(argv[0], "unregister") == 0) {
/* Unregisters a package from the database */
if (argc != 3)
usage();
usage(xhp);
if (!xbps_remove_pkg_dict_from_plist_by_name(argv[1], plist)) {
if (errno == ENOENT)
@ -239,7 +240,7 @@ main(int argc, char **argv)
} else if (strcasecmp(argv[0], "version") == 0) {
/* Prints version of an installed package */
if (argc != 2)
usage();
usage(xhp);
dict = xbps_find_pkg_dict_from_plist_by_name(plist,
"packages", argv[1]);
@ -253,7 +254,7 @@ main(int argc, char **argv)
} else if (strcasecmp(argv[0], "sanitize-plist") == 0) {
/* Sanitize a plist file (properly indent the file) */
if (argc != 2)
usage();
usage(xhp);
dict = prop_dictionary_internalize_from_zfile(argv[1]);
if (dict == NULL) {
@ -267,7 +268,7 @@ main(int argc, char **argv)
} else if (strcasecmp(argv[0], "getpkgversion") == 0) {
/* Returns the version of a pkg string */
if (argc != 2)
usage();
usage(xhp);
version = xbps_pkg_version(argv[1]);
if (version == NULL) {
@ -280,7 +281,7 @@ main(int argc, char **argv)
} else if (strcasecmp(argv[0], "getpkgname") == 0) {
/* Returns the name of a pkg string */
if (argc != 2)
usage();
usage(xhp);
pkgname = xbps_pkg_name(argv[1]);
if (pkgname == NULL) {
@ -294,7 +295,7 @@ main(int argc, char **argv)
} else if (strcasecmp(argv[0], "getpkgrevision") == 0) {
/* Returns the revision of a pkg string */
if (argc != 2)
usage();
usage(xhp);
version = xbps_pkg_revision(argv[1]);
if (version == NULL)
@ -305,7 +306,7 @@ main(int argc, char **argv)
} else if (strcasecmp(argv[0], "getpkgdepname") == 0) {
/* Returns the pkgname of a dependency */
if (argc != 2)
usage();
usage(xhp);
pkgname = xbps_pkgpattern_name(argv[1]);
if (pkgname == NULL)
@ -316,7 +317,7 @@ main(int argc, char **argv)
} else if (strcasecmp(argv[0], "getpkgdepversion") == 0) {
/* returns the version of a package pattern dependency */
if (argc != 2)
usage();
usage(xhp);
version = xbps_pkgpattern_version(argv[1]);
if (version == NULL)
@ -327,21 +328,21 @@ main(int argc, char **argv)
} else if (strcasecmp(argv[0], "pkgmatch") == 0) {
/* Matches a pkg with a pattern */
if (argc != 3)
usage();
usage(xhp);
exit(xbps_pkgpattern_match(argv[1], argv[2]));
} else if (strcasecmp(argv[0], "cmpver") == 0) {
/* Compare two version strings, installed vs required */
if (argc != 3)
usage();
usage(xhp);
exit(xbps_cmpver(argv[1], argv[2]));
} else if (strcasecmp(argv[0], "digest") == 0) {
/* Prints SHA256 hashes for specified files */
if (argc < 2)
usage();
usage(xhp);
for (i = 1; i < argc; i++) {
hash = xbps_file_hash(argv[i]);
@ -358,7 +359,7 @@ main(int argc, char **argv)
} else if (strcasecmp(argv[0], "fetch") == 0) {
/* Fetch a file from specified URL */
if (argc != 2)
usage();
usage(xhp);
for (i = 1; i < argc; i++) {
rv = xbps_fetch_file(argv[i], ".", false, "v");
@ -373,7 +374,7 @@ main(int argc, char **argv)
}
} else {
usage();
usage(xhp);
}
xbps_end(xhp);