comparison imgupd-clean.c @ 7:1cf90affaa33

misc: rename the project to imgup
author David Demelier <markand@malikania.fr>
date Thu, 26 Nov 2020 19:13:08 +0100
parents
children f19f5f9fee56
comparison
equal deleted inserted replaced
6:882acedb9b89 7:1cf90affaa33
1 /*
2 * imgupd-clean.c -- main imgupd-clean(8) file
3 *
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #include <limits.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <stdnoreturn.h>
23 #include <unistd.h>
24
25 #include "database.h"
26 #include "util.h"
27
28 static noreturn void
29 usage(void)
30 {
31 fprintf(stderr, "usage: imgupd-clean [-d database-path]\n");
32 exit(1);
33 }
34
35 int
36 main(int argc, char **argv)
37 {
38 const char *value;
39 char path[PATH_MAX] = VARDIR "/imgup/imgup.db";
40 int ch;
41
42 /* Seek environment first. */
43 if ((value = getenv("IMGUPD_DATABASE_PATH")))
44 snprintf(path, sizeof (path), "%s", value);
45
46 while ((ch = getopt(argc, argv, "d:")) != -1) {
47 switch (ch) {
48 case 'd':
49 snprintf(path, sizeof (path), "%s", optarg);
50 break;
51 default:
52 usage();
53 break;
54 }
55 }
56
57 if (!path[0])
58 die("abort: no database specified");
59 if (!database_open(path))
60 die("abort: could not open database");
61
62 database_clear();
63 database_finish();
64 }