Skip to content

Instantly share code, notes, and snippets.

@Orc
Created May 19, 2017 20:00
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 Orc/4c8a5cf285c3f1324ae18d796d9a7246 to your computer and use it in GitHub Desktop.
Save Orc/4c8a5cf285c3f1324ae18d796d9a7246 to your computer and use it in GitHub Desktop.
print a file date in a git-aware form (needed by pull.sh)
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <libgen.h>
#include <time.h>
main(argc, argv)
char **argv;
{
struct stat st;
struct tm time;
char timestamp[80];
char *pgm = basename(argv[0]);
if ( argc < 2 ) {
fprintf(stderr, "usage: %s file\n", pgm);
exit(1);
}
if ( stat(argv[1], &st) == -1 ) {
perror(argv[1]);
exit(1);
}
/* 2005-04-07T22:13:13 */
strftime(timestamp, sizeof timestamp, "%Y-%m-%d %H:%M:%S", gmtime(&st.st_mtime));
puts(timestamp);
exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment