Skip to content

Instantly share code, notes, and snippets.

@hasandiwan
Created June 1, 2023 08:01
Show Gist options
  • Save hasandiwan/0f1d581c1a274884cc790317a3865b50 to your computer and use it in GitHub Desktop.
Save hasandiwan/0f1d581c1a274884cc790317a3865b50 to your computer and use it in GitHub Desktop.
Port of perl's -M function to C
#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;
}
$ 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