summaryrefslogtreecommitdiff
path: root/src/util/fs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/fs.c')
-rw-r--r--src/util/fs.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/util/fs.c b/src/util/fs.c
new file mode 100644
index 0000000..6f787c0
--- /dev/null
+++ b/src/util/fs.c
@@ -0,0 +1,23 @@
+#include "fs.h"
+
+bool is_dir(const char *restrict pathname) {
+#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));
+}
+
+const char *myhome() {
+ 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;
+}