utime() can be used to change timestamps of files (timestomping). utime() only supports second-level precision, not nanoseconds.
This function is better suited to older systems that lack utimensat() and was deprecated in POSIX.1-2008.
#include <utime.h>
#include <stdio.h>
#include <time.h>
int main() {
struct utimbuf new_times;
new_times.actime = 1672531200; // Access time: Jan 1, 2023
new_times.modtime = 1672534800; // Modification time: Jan 1, 2023
if (utime("example.txt", &new_times) == -1) {
perror("utime");
return 1;
}
printf("Timestamps updated using utime().\n");
return 0;
}