Project

General

Profile

Bug #3251 ยป link_ctime.c

tonyc, 10/25/2020 06:00 PM

 
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>

int main(void) {
int fd = open("testfile", O_CREAT | O_RDWR, 0600);
struct stat st1, st2;

if (fd < 0) {
perror("NA: open");
exit(1);
}
if (close(fd) < 0) {
perror("NA: close");
exit(1);
}

unlink("testlink");
if (stat("testfile", &st1) < 0) {
perror("NA: first stat");
exit(1);
}
sleep(5);

if (chmod("testfile", 0660) < 0) {
perror("NA: chmod");
exit(1);
}
if (stat("testfile", &st2) < 0) {
perror("NA: second stat");
exit(1);
}
if (st2.st_ctim.tv_sec == st1.st_ctim.tv_sec) {
printf("FAIL: chmod didn't update ctime\n");
}
else {
printf("OK: chmod updated ctime\n");
}
st1 = st2;
sleep(5);
if (link("testfile", "testlink") < 0) {
perror("NA: link failed");
exit(1);
}
if (stat("testfile", &st2) < 0) {
perror("NA: third stat");
exit(1);
}
if (st2.st_ctim.tv_sec == st1.st_ctim.tv_sec) {
printf("FAIL: link didn't update ctime\n");
exit(1);
}
else {
printf("OK: link updated ctime\n");
}
return 0;
}
    (1-1/1)