Created
April 12, 2015 00:52
-
-
Save samthor/af9b25480ca9b5443b09 to your computer and use it in GitHub Desktop.
nanosecond mtime to console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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