#include #include #include #include #include #include #include #define F_PATH "utime-test.c" int main() { struct stat sb; struct utimbuf ub; int fd; if (stat(F_PATH, &sb) == -1) { perror(NULL); return -1; } ub.modtime = sb.st_mtime; ub.actime = time(NULL); if (utime(F_PATH, &ub) == -1) { perror(NULL); return -2; } if ((fd = open(F_PATH, O_RDONLY)) == -1) { perror(NULL); return -3; } close(fd); if (stat(F_PATH, &sb) == -1) { perror(NULL); return -1; } ub.modtime = sb.st_mtime; ub.actime = time(NULL); if (utime(F_PATH, &ub) == -1) { perror(NULL); return -2; } return 0; }