summaryrefslogtreecommitdiffstats
path: root/util.h
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2016-12-04 11:39:55 -0500
committerTavian Barnes <tavianator@tavianator.com>2016-12-04 11:39:55 -0500
commit49e767ccb9dcfd2161b89f0d7a980eb85f056c5d (patch)
tree3cdb06282e30c02e3b37615d39b5c1c75af53e3d /util.h
parent6962fb41b8e57f8bc817b477cf16262a0ce876d5 (diff)
downloadbfs-49e767ccb9dcfd2161b89f0d7a980eb85f056c5d.tar.xz
Move portability code into util.h
Diffstat (limited to 'util.h')
-rw-r--r--util.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/util.h b/util.h
index fbcadbd..e814f23 100644
--- a/util.h
+++ b/util.h
@@ -14,6 +14,27 @@
#include <dirent.h>
#include <stdbool.h>
+#include <sys/stat.h>
+
+// Some portability concerns
+
+#if __APPLE__
+# define st_atim st_atimespec
+# define st_ctim st_ctimespec
+# define st_mtim st_mtimespec
+#endif
+
+#ifndef S_ISDOOR
+# define S_ISDOOR(mode) false
+#endif
+
+#ifndef S_ISPORT
+# define S_ISPORT(mode) false
+#endif
+
+#ifndef S_ISWHT
+# define S_ISWHT(mode) false
+#endif
/**
* readdir() wrapper that makes error handling cleaner.
@@ -40,4 +61,13 @@ bool isopen(int fd);
*/
int redirect(int fd, const char *path, int flags, ...);
+/**
+ * Like dup(), but set the FD_CLOEXEC flag.
+ *
+ * @param fd
+ * The file descriptor to duplicate.
+ * @return A duplicated file descriptor, or -1 on failure.
+ */
+int dup_cloexec(int fd);
+
#endif // BFS_UTIL_H