+#include <unistd.h>
+
+#include "wimlib/blob_table.h"
+#include "wimlib/capture.h"
+#include "wimlib/dentry.h"
+#include "wimlib/error.h"
+#include "wimlib/reparse.h"
+#include "wimlib/timestamp.h"
+#include "wimlib/unix_data.h"
+
+#ifdef HAVE_FDOPENDIR
+# define my_fdopendir(dirfd_p) fdopendir(*(dirfd_p))
+#else
+static DIR *
+my_fdopendir(int *dirfd_p)
+{
+ DIR *dir = NULL;
+ int old_pwd;
+
+ old_pwd = open(".", O_RDONLY);
+ if (old_pwd >= 0) {
+ if (!fchdir(*dirfd_p)) {
+ dir = opendir(".");
+ if (dir) {
+ close(*dirfd_p);
+ *dirfd_p = dirfd(dir);
+ }
+ fchdir(old_pwd);
+ }
+ close(old_pwd);
+ }
+ return dir;
+}
+#endif
+
+#ifdef HAVE_OPENAT
+# define my_openat(full_path, dirfd, relpath, flags) \
+ openat((dirfd), (relpath), (flags))
+#else
+# define my_openat(full_path, dirfd, relpath, flags) \
+ open((full_path), (flags))
+#endif
+
+#ifdef HAVE_READLINKAT
+# define my_readlinkat(full_path, dirfd, relpath, buf, bufsize) \
+ readlinkat((dirfd), (relpath), (buf), (bufsize))
+#else
+# define my_readlinkat(full_path, dirfd, relpath, buf, bufsize) \
+ readlink((full_path), (buf), (bufsize))
+#endif
+
+#ifdef HAVE_FSTATAT
+# define my_fstatat(full_path, dirfd, relpath, stbuf, flags) \
+ fstatat((dirfd), (relpath), (stbuf), (flags))
+#else
+# define my_fstatat(full_path, dirfd, relpath, stbuf, flags) \
+ ((flags) & AT_SYMLINK_NOFOLLOW) ? \
+ lstat((full_path), (stbuf)) : \
+ stat((full_path), (stbuf))
+#endif
+
+#ifndef AT_FDCWD
+# define AT_FDCWD -100
+#endif
+
+#ifndef AT_SYMLINK_NOFOLLOW
+# define AT_SYMLINK_NOFOLLOW 0x100
+#endif