Created
June 1, 2023 08:01
-
-
Save hasandiwan/0f1d581c1a274884cc790317a3865b50 to your computer and use it in GitHub Desktop.
Port of perl's -M function to C
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
#include <stdio.h> | |
#include <sys/stat.h> | |
#include <time.h> | |
int main(int argc, char **argv) { | |
struct stat sb; | |
int rv; | |
rv = stat(argv[argc-1], &sb); | |
fprintf(stdout, "%ld\n", (time(NULL)-sb.st_atime)/86400); | |
return rv; | |
} |
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
$ clang ./fileAgeInDays.c -o timeInDays | |
$ ./timeInDays # gives the file age in days | |
./timeInDays -- 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment