int futimens_opath(int fd, const struct timespec ts[2]) {
/* Similar to fchmod_opath() but for futimens() */
- if (utimensat(AT_FDCWD, FORMAT_PROC_FD_PATH(fd), ts, 0) < 0) {
+ assert(fd >= 0);
+
+ if (utimensat(fd, "", ts, AT_EMPTY_PATH) >= 0)
+ return 0;
+ if (errno != EINVAL)
+ return -errno;
+
+ /* Support for AT_EMPTY_PATH is added rather late (kernel 5.8), so fall back to going through /proc/
+ * if unavailable. */
+
+ if (utimensat(AT_FDCWD, FORMAT_PROC_FD_PATH(fd), ts, /* flags = */ 0) < 0) {
if (errno != ENOENT)
return -errno;
if (proc_mounted() == 0)
- return -ENOSYS; /* if we have no /proc/, the concept is not implementable */
+ return -ENOSYS;
return -ENOENT;
}