summaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2021-03-06 14:06:01 -0500
committerTavian Barnes <tavianator@tavianator.com>2021-03-06 14:10:24 -0500
commitfeb349458e8ae17ede636716ccfa9d97e63f30b1 (patch)
treeb9dd312a3f6ce3e9f7adaa52ced64f124da1b0c3 /util.c
parent863b70d198f62f28581162473a521208dd67879e (diff)
downloadbfs-feb349458e8ae17ede636716ccfa9d97e63f30b1.tar.xz
Support -flags on all the BSDs
Diffstat (limited to 'util.c')
-rw-r--r--util.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/util.c b/util.c
index f271dce..63ea756 100644
--- a/util.c
+++ b/util.c
@@ -39,6 +39,10 @@
# include <sys/mkdev.h>
#endif
+#if BFS_HAS_UTIL
+# include <util.h>
+#endif
+
char *xreadlinkat(int fd, const char *path, size_t size) {
ssize_t len;
char *name = NULL;
@@ -232,6 +236,32 @@ int xfaccessat(int fd, const char *path, int amode) {
return ret;
}
+int xstrtofflags(const char **str, unsigned long long *set, unsigned long long *clear) {
+#if BSD
+ char *str_arg = (char *)*str;
+ unsigned long set_arg = 0;
+ unsigned long clear_arg = 0;
+
+#if __NetBSD__
+ int ret = string_to_flags(&str_arg, &set_arg, &clear_arg);
+#else
+ int ret = strtofflags(&str_arg, &set_arg, &clear_arg);
+#endif
+
+ *str = str_arg;
+ *set = set_arg;
+ *clear = clear_arg;
+
+ if (ret != 0) {
+ errno = EINVAL;
+ }
+ return ret;
+#else // !BSD
+ errno = ENOTSUP;
+ return -1;
+#endif
+}
+
bool is_nonexistence_error(int error) {
return error == ENOENT || errno == ENOTDIR;
}