aboutsummaryrefslogtreecommitdiffstats
path: root/libcontacts_get_path.c
blob: cc20b7dc8988f5d30fe0d081365f65d7ece68948 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/* See LICENSE file for copyright and license details. */
#include "common.h"


char *
libcontacts_get_path(const char *id, const struct passwd *user)
{
	size_t len;
	char *buf;

	if (!id || !user || !user->pw_dir || !*user->pw_dir) {
		errno = EINVAL;
		return NULL;
	}

	len = strlen(user->pw_dir) + sizeof("/.config/contacts/") + strlen(id);
	buf = malloc(len);
	if (!buf)
		return NULL;

	stpcpy(stpcpy(stpcpy(buf, user->pw_dir), "/.config/contacts/"), id);
	return buf;
}