summaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
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;
}