summaryrefslogtreecommitdiff
path: root/src/skonfig.c
diff options
context:
space:
mode:
authorDennis Camera <skonfig@dtnr.ch>2022-08-03 17:41:14 +0200
committerDennis Camera <skonfig@dtnr.ch>2022-08-03 17:58:16 +0200
commit26f555c974cf49def75120dada596f421e15f1d4 (patch)
treee45fdac5f17b04b3fb15dfd1079a9560ba9de259 /src/skonfig.c
parent1fc6697f4de4290575202661b664ca617df9b8e1 (diff)
downloadskonfig-c-26f555c974cf49def75120dada596f421e15f1d4.tar.gz
skonfig-c-26f555c974cf49def75120dada596f421e15f1d4.zip
Move helper functions out to src/util/
Diffstat (limited to 'src/skonfig.c')
-rw-r--r--src/skonfig.c52
1 files changed, 5 insertions, 47 deletions
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 <stdio.h>
#include <stdlib.h>
-#include <string.h>
#include <unistd.h>
-#include <limits.h>
-#include <pwd.h>
-#include <sys/stat.h>
#if HAVE_STDBOOL_H
#include <stdbool.h>
@@ -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 */