aboutsummaryrefslogtreecommitdiff
path: root/mbpk.c
blob: 30ec82de1015a582c64b7fd7315e1945bac45b27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <pwd.h>
#include <xbps.h>
#include <stdlib.h>
#include <limits.h>

int main(void) {
	/* init xbps stuff */
	struct xbps_handle x;

	memset(&x, 0, sizeof(x));
	const char* home = getenv("HOME");
	if (home == NULL) {
		struct passwd *pw = getpwuid(getuid());
		if (pw != NULL) {
			home = pw->pw_dir;
		}
	}
	snprintf(x.rootdir, sizeof(x.rootdir), "%s/.local/mbpk/prefix", home);
	snprintf(x.cachedir, sizeof(x.cachedir), "%s/.local/mbpk/cache", home);
	snprintf(x.confdir, sizeof(x.confdir), "%s/.local/mbpk/conf.d", home);
	x.flags = XBPS_FLAG_VERBOSE;

	int r = xbps_init(&x);
	if (r != 0) {
		fprintf(stderr, "xbps_init failed: %s\n", strerror(r));
		return r;
	}

	return 0;
}