comparison imgpasterd-clean.c @ 0:f41e1b48510d

misc: initial import
author David Demelier <markand@malikania.fr>
date Wed, 25 Nov 2020 21:13:03 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f41e1b48510d
1 /*
2 * pasterd-clean.c -- main pasterd-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: imgpasterd-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 "/imgpaster/imgpaster.db";
40 int ch;
41
42 /* Seek environment first. */
43 if ((value = getenv("IMGPASTERD_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 }