From cc00928022a5739378371d23c4b7f64e71797ade Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Mon, 17 Sep 2018 12:05:13 +0000 Subject: [PATCH] add error checks to foreach_path add usage message to foreach-path fix path for local database --- lib/foreach_path.c | 3 +++ zpm-foreach-path.c | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/foreach_path.c b/lib/foreach_path.c index 271ee8c..b73739b 100644 --- a/lib/foreach_path.c +++ b/lib/foreach_path.c @@ -20,6 +20,8 @@ void *data, char **errmsg) { char *sql; + if (!zpm || zpm->error || !pkgid || !callback) return 0; + sql = sqlite3_mprintf(files, pkgid); if (!sql) { return 0; @@ -31,6 +33,7 @@ void *data, char **errmsg) { zpm->error = 2; return 0; } + sqlite3_free(sql); return 1; } diff --git a/zpm-foreach-path.c b/zpm-foreach-path.c index 30340a0..2403576 100644 --- a/zpm-foreach-path.c +++ b/zpm-foreach-path.c @@ -24,7 +24,7 @@ struct config { }; static void usage() { - printf("usage: ...\n"); + printf("usage: zpm foreach-path [-fncC] args ...\n"); } static int run_program(void *f, int ncols, char **vals, char **cols) { @@ -200,10 +200,9 @@ int main(int ac, char **av){ char *s; int opt; - struct config conf = { "/var/lib/db.zpm", 0, 0, 0, "", 0, 0, printpaths + struct config conf = { "/var/lib/zpm/local.db", 0, 0, 0, "", 0, 0, printpaths }; - if ((s = getenv("ZPMDB"))) { /* TODO does this need to be copied ? */ conf.dbfile = s; @@ -252,6 +251,7 @@ int main(int ac, char **av){ argn++; } else { fprintf(stderr, "must specify pkgid\n"); + usage(); exit(EXIT_FAILURE); } -- 2.40.0