+ errno = ENOSYS;
+#ifdef HAVE_FUTIMENS
+ if (fd >= 0 && !futimens(fd, times))
+ return 0;
+#endif
+#ifdef HAVE_UTIMENSAT
+ if (fd < 0 && !utimensat(AT_FDCWD, path, times, AT_SYMLINK_NOFOLLOW))
+ return 0;
+#endif
+ if (errno != ENOSYS)
+ return WIMLIB_ERR_SET_TIMESTAMPS;
+ }
+ {
+ struct timeval times[2];
+
+ times[0] = wim_timestamp_to_timeval(atime);
+ times[1] = wim_timestamp_to_timeval(mtime);
+
+ if (fd >= 0 && !futimes(fd, times))
+ return 0;
+ if (fd < 0 && !lutimes(path, times))
+ return 0;
+ return WIMLIB_ERR_SET_TIMESTAMPS;
+ }
+}
+
+static int
+unix_set_owner_and_group(int fd, const char *path, uid_t uid, gid_t gid)
+{
+ if (fd >= 0 && !fchown(fd, uid, gid))
+ return 0;
+ if (fd < 0 && !lchown(path, uid, gid))
+ return 0;
+ return WIMLIB_ERR_SET_SECURITY;
+}
+
+static int
+unix_set_mode(int fd, const char *path, mode_t mode)
+{
+ if (fd >= 0 && !fchmod(fd, mode))
+ return 0;
+ if (fd < 0 && !chmod(path, mode))
+ return 0;
+ return WIMLIB_ERR_SET_SECURITY;
+}
+
+#ifdef HAVE_XATTR_SUPPORT
+/* Apply extended attributes to a file */
+static int
+apply_linux_xattrs(int fd, const struct wim_inode *inode,
+ const char *path, struct unix_apply_ctx *ctx,
+ const void *entries, size_t entries_size)
+{
+ const void * const entries_end = entries + entries_size;
+ char name[XATTR_NAME_MAX + 1];
+
+ for (const struct wimlib_xattr_entry *entry = entries;
+ (void *)entry < entries_end; entry = xattr_entry_next(entry))
+ {
+ u16 name_len;
+ const void *value;
+ u32 value_len;
+ int res;
+
+ if (!valid_xattr_entry(entry, entries_end - (void *)entry)) {
+ if (!path) {
+ path = unix_build_inode_extraction_path(inode,
+ ctx);
+ }
+ ERROR("\"%s\": extended attribute is corrupt", path);
+ return WIMLIB_ERR_INVALID_XATTR;