summaryrefslogtreecommitdiff
path: root/fdate.c
blob: 5a25803b1348aee1a8e76a8517df295c431a06fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* reads a filename from stdin and prints its time-last-modified,
   in format [d]d <Month-name> yyyy */

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <time.h>

struct stat buf;
struct tm *t;

char *month[] = {"January","February","March","April","May","June",
                "July","August","September","October","November","December"};
int main()
{ char f[200];
  if(scanf("%s",f)==1&&stat(f,&buf)==0)
    t=localtime(&buf.st_mtime),
    printf("%d %s %4d\n",(*t).tm_mday,month[(*t).tm_mon],(*t).tm_year+1900);
  else fprintf(stderr,"fdate: bad file \"%s\"\n",f);
}