home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / FDATE.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  1KB  |  73 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  Public domain by Bob Stout
  5. */
  6.  
  7. #if !defined(__TURBOC__) && !defined(__SC__)
  8.  #include "ftime.h"
  9. #endif
  10. #include <io.h>
  11. #include <fcntl.h>
  12. #include "ftime.h"
  13. #include "scaldate.h"
  14.  
  15. /*
  16. **  getfdate() - Return DOS file (handle) date as a SNIPPETS scalar date
  17. */
  18.  
  19. int getfdate (int handle, long *date)
  20. {
  21.       static struct ftime ftimep;
  22.       int retval = 0;
  23.  
  24.       if (0 == (retval = getftime(handle, &ftimep)))
  25.       {
  26.             *date = ymd_to_scalar(ftimep.ft_year + 1980, ftimep.ft_month,
  27.                   ftimep.ft_day);
  28.       }
  29.       return retval;
  30. }
  31.  
  32. /*
  33. **  getdatef() - Return DOS file (filename) date as a SNIPPETS scalar date
  34. */
  35.  
  36. int getdatef (char *fname, long *date)
  37. {
  38.       int fh;
  39.  
  40.       if (-1 != (fh = open(fname, O_RDONLY, 0)))
  41.       {
  42.             int retval;
  43.  
  44.             retval = getfdate(fh, date);
  45.             close(fh);
  46.             return retval;
  47.       }
  48.       else  return fh;
  49. }
  50.  
  51. #ifdef TEST
  52.  
  53. #include <stdio.h>
  54.  
  55. main(int argc, char *argv[])
  56. {
  57.       long date;
  58.  
  59.       while (--argc)
  60.       {
  61.             if (0 == getdatef(*++argv, &date))
  62.             {
  63.                   unsigned yr, mo, dy;
  64.  
  65.                   scalar_to_ymd(date, &yr, &mo, &dy);
  66.                   printf("%-15s: %2d/%02d/%04d\n", *argv, mo, dy, yr);
  67.             }
  68.       }
  69.       return 0;
  70. }
  71.  
  72. #endif /* TEST */
  73.