From 26f555c974cf49def75120dada596f421e15f1d4 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Wed, 3 Aug 2022 17:41:14 +0200 Subject: Move helper functions out to src/util/ --- src/skonfig.c | 52 +++++----------------------------------------------- 1 file changed, 5 insertions(+), 47 deletions(-) (limited to 'src/skonfig.c') diff --git a/src/skonfig.c b/src/skonfig.c index b5ab37b..08169fd 100644 --- a/src/skonfig.c +++ b/src/skonfig.c @@ -1,12 +1,13 @@ #include "../config.h" +#include "config.h" +#include "util/array.h" +#include "util/fs.h" +#include "util/string.h" + #include #include -#include #include -#include -#include -#include #if HAVE_STDBOOL_H #include @@ -26,49 +27,6 @@ struct sk_options { static const char *EXECNAME = PACKAGE; /* default */ -/* utils */ - -#define arraylen(a) (sizeof(a)/sizeof(*a)) - -static bool is_dir(const char * restrict pathname) { - /** - * Check if a given pathname is a directory. - * - * @returns true if the given pathname exists and is a directory, false - * otherwise. - */ -#ifdef STAT_MACROS_BROKEN -#error stat() macros are broken on this system. Cannot compile is_dir(). -#endif - struct stat s; - return (0 == stat(pathname, &s) && S_ISDIR(s.st_mode)); -} - -static const char *myhome() { - /** - * Returns a pointer to a string containing the current user’s home - * directory. - * The returned pointer points to a static location (don’t free() it) and - * may be changed on future invocations. - * - * This function makes sure that the returned string is null-terminated and - * truncates the result to fit within PATH_MAX if necessary. - * - * @returns home dir - */ - static char home[PATH_MAX+1]; - - home[0] = '\0'; - if (!getenv("HOME")) { - (void)strncpy(home, getenv("HOME"), PATH_MAX); - } else { /* HOME unset or empty */ - (void)strncpy(home, getpwuid(getuid())->pw_dir, PATH_MAX); - } - home[PATH_MAX] = '\0'; - - return (const char *)&home; -} - /* help */ -- cgit v1.2.3