#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#define TARGET_FILE_NAME "/tmp/test"
int main(void)
{
struct stat st;
struct timespec start, end;
unsigned long long elapse;
int ret;
ret = clock_gettime(CLOCK_REALTIME, &start);
if (ret < 0) {
fprintf(stderr, "Unable to get start timestamp
");
return ret;
}
ret = lstat(TARGET_FILE_NAME, &st);
if (ret < 0) {
fprintf(stderr, "Error on lstat()
");
return ret;
}
ret = clock_gettime(CLOCK_REALTIME, &end);
if (ret < 0) {
fprintf(stderr, "Unable to get end timestamp
");
return ret;
}
elapse = (end.tv_sec - start.tv_sec) * 1000000000 +
(end.tv_nsec - start.tv_nsec);
fprintf(stdout, "elapse: %lld ns
", elapse);
return 0;
}