]> pd.if.org Git - zpackage/blob - lib/foreach_path.c
cleanup and fix bugs in addfile
[zpackage] / lib / foreach_path.c
1 #define _POSIX_C_SOURCE 2
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <sys/types.h>
5 #include <sys/wait.h>
6
7 #include <string.h>
8
9 #include "sqlite3.h"
10 #include "zpm.h"
11
12 int zpm_foreach_path(struct zpm *zpm, char *pkgid, 
13 int (*callback)(void *f, int ncols, char **vals, char **cols),
14 void *data, char **errmsg) {
15
16         char *files = "select * from packagefiles where"
17                 " printf('%%s-%%s-%%s', package, version, release) = %Q"
18                 " order by path"
19                 ;
20
21         char *sql;
22
23         if (!zpm || zpm->error || !pkgid || !callback) return 0;
24
25         sql = sqlite3_mprintf(files, pkgid);
26         if (!sql) {
27                 return 0;
28                 zpm->error = 1;
29         }
30
31         zpm_exec(zpm, sql, callback, data, errmsg);
32         if (errmsg) {
33                 zpm->error = 2;
34                 return 0;
35         }
36         sqlite3_free(sql);
37
38         return 1;
39 }