futimens: do not require O_RWONLY/O_RDWR
This code, for example, should work (and does on Linux).
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
int main() {
int fd = open("test.txt", O_RDONLY);
struct timespec times[2] = {{0, 0}, {0, 0}};
if (fd == -1) {
perror("open");
exit(1);
}
if (futimens(fd, times) == -1) {
perror("futimens");
exit(1);
}
}
The specific situation where I came across this was code that chmod
ed a file to be read only then set the times.