From 8b52cc7243c2e0e4ef17db5583999030b8636584 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 2 Apr 2021 13:17:25 +0200 Subject: First commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libcontacts_get_path.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 libcontacts_get_path.c (limited to 'libcontacts_get_path.c') diff --git a/libcontacts_get_path.c b/libcontacts_get_path.c new file mode 100644 index 0000000..cc20b7d --- /dev/null +++ b/libcontacts_get_path.c @@ -0,0 +1,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; +} -- cgit v1.2.3-70-g09d2