/***********************************************************************
*
*   tstamp.c
*
*   A command to be used to display the access, modification, and status
*   timestamps of given files. 
*
*   Author: chux0r.org (C) 2001. Licensed under the LGPL:
*           http://www.gnu.org/copyleft/lesser.txt 
*
*
*   USAGE: $ tstamp /path/file1 /path2/file2, ... /pathn/filen
*
*   17 Oct 2001
*
*
************************************************************************/

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

int main(int argc, char* argv[])
   {
   int		i,
   		err;
   struct stat 	statbuff;
   char		*adate_str,
                *mdate_str,
		*cdate_str;
   if(argc < 1 || argv[1] == "-h")
      {
      printf("USAGE: tstamp [-h]  /path/file1 /path2/file2,.../pathn/filen");
      exit(0);
      }
   for(i=1; i<argc ; i++)
      {
      err=0;
      if(stat(argv[i], &statbuff) < 0)
         {
         printf("file: %s not found\n",argv[i]);
         err=1;
         }
      else if(ctime(&statbuff.st_atime) == NULL || \
              ctime(&statbuff.st_mtime) == NULL || \
              ctime(&statbuff.st_ctime) == NULL)
         {
         printf("%s: ERROR: Invalid timestring given.",argv[i]); 
         err=1;
         }
      if(err==0)
         {
         adate_str=ctime(&statbuff.st_atime);
         mdate_str=ctime(&statbuff.st_mtime);
         cdate_str=ctime(&statbuff.st_ctime);
         printf("%s:\n\tatime: %s\tmtime: %s\tctime: %s\n",argv[i],adate_str,mdate_str,cdate_str);
         }
      }
   return(0);
   }
