Skip to content

Instantly share code, notes, and snippets.

@samthor
Created April 12, 2015 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samthor/af9b25480ca9b5443b09 to your computer and use it in GitHub Desktop.
Save samthor/af9b25480ca9b5443b09 to your computer and use it in GitHub Desktop.
nanosecond mtime to console
// nano.c: writes nanosecond mtime of first arg to console
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <time.h>
#define SEC_TO_NANO 1000000000
int main(int argc, char **argv) {
if (argc != 2) {
return 1;
}
char *file = argv[1];
struct stat s;
stat(file, &s);
long long out;
out = ((long long) s.st_mtim.tv_sec) * SEC_TO_NANO;
out += (long long) s.st_mtim.tv_nsec;
printf("%lld\n", out);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment