summaryrefslogtreecommitdiff
path: root/src/util/fs.c
blob: 6f787c0fbb1454a15c53ccf88d64700849ca6cf0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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;
}