/* reads a filename from stdin and prints its time-last-modified,
   in format [d]d <Month-name> yyyy */

#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>

#ifndef PATH_MAX
#ifdef _XOPEN_PATH_MAX
#define PATH_MAX _XOPEN_PATH_MAX
#else
#define PATH_MAX _POSIX_PATH_MAX
#endif
#endif

int main(void)
{
  char buf[PATH_MAX];
  if (scanf("%s", buf) != 1) {
    fprintf(stderr, "fdate: invalid input\n");
    return 1;
  }

  struct stat st;
  if (stat(buf, &st) != 0) {
    fprintf(stderr, "fdate: error reading date from \"%s\": %s\n", buf,
      strerror(errno));
    return 1;
  }

  struct tm *tm = localtime(&st.st_mtime);
  strftime(buf, sizeof(buf), "%d %B %Y", tm);
  puts(buf[0] == '0' ? buf + 1 : buf);
  return 0;
}