Skip to content

futimens: do not require O_RWONLY/O_RDWR

Ian Douglas Scott requested to merge ids1024:utimens into master

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 chmoded a file to be read only then set the times.

Merge request reports