diff options
| author | Dennis Camera <skonfig@dtnr.ch> | 2022-08-03 17:41:14 +0200 |
|---|---|---|
| committer | Dennis Camera <skonfig@dtnr.ch> | 2022-08-03 17:58:16 +0200 |
| commit | 26f555c974cf49def75120dada596f421e15f1d4 (patch) | |
| tree | e45fdac5f17b04b3fb15dfd1079a9560ba9de259 /src/util/fs.c | |
| parent | 1fc6697f4de4290575202661b664ca617df9b8e1 (diff) | |
| download | skonfig-c-26f555c974cf49def75120dada596f421e15f1d4.tar.gz skonfig-c-26f555c974cf49def75120dada596f421e15f1d4.zip | |
Move helper functions out to src/util/
Diffstat (limited to 'src/util/fs.c')
| -rw-r--r-- | src/util/fs.c | 23 |
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; +} |
