aboutsummaryrefslogblamecommitdiffstats
path: root/libcontacts_get_path.c
blob: cc20b7dc8988f5d30fe0d081365f65d7ece68948 (plain) (tree)






















                                                                               
/* 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;
}