Created
May 19, 2017 20:00
-
-
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)
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 <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