home *** CD-ROM | disk | FTP | other *** search
/ ftp.ncftp.com / ftp.ncftp.com.zip / ftp.ncftp.com / ncftp / older_versions / ncftp-3.2.2-src.tar.bz2 / ncftp-3.2.2-src.tar / ncftp-3.2.2 / libncftp / u_unmdtm.c < prev    next >
C/C++ Source or Header  |  2008-07-13  |  1KB  |  67 lines

  1. /* u_unmdtm.c
  2.  *
  3.  * Copyright (c) 1996-2005 Mike Gleason, NcFTP Software.
  4.  * All rights reserved.
  5.  *
  6.  */
  7.  
  8. #include "syshdrs.h"
  9. #ifdef PRAGMA_HDRSTOP
  10. #    pragma hdrstop
  11. #endif
  12.  
  13. #define _CRT_SECURE_NO_WARNINGS 1
  14.  
  15. /* Converts a MDTM date, like "19930602204445"
  16.  * format to a time_t.
  17.  */
  18. time_t UnMDTMDate(char *dstr)
  19. {
  20. #ifndef HAVE_MKTIME
  21.     return (kModTimeUnknown);
  22. #else
  23.     struct tm ut;
  24.     time_t mt, now;
  25.     time_t result = kModTimeUnknown;
  26.     char y2fix[64];
  27.  
  28.     if (strncmp(dstr, "1910", 4) == 0) {
  29.         /* Server Y2K bug! */
  30.         memset(y2fix, 0, sizeof(y2fix));
  31.         y2fix[0] = '2';
  32.         y2fix[1] = '0';
  33.         y2fix[2] = dstr[3];
  34.         y2fix[3] = dstr[4];
  35.         strncpy(y2fix + 4, dstr + 5, sizeof(y2fix) - 6);
  36.         dstr = y2fix;
  37.     }
  38.  
  39.     /* Get a fully populated struct tm.  We do this so we don't have
  40.      * to set all fields ourselves, i.e., non-standard fields such as
  41.      * tm_gmtoff, if it exists or not.
  42.      */
  43.     if (Gmtime(time(&now), &ut) == NULL)
  44.         return result;
  45.  
  46.     /* The time we get back from the server is (should be) in UTC. */
  47.     if (sscanf(dstr, "%04d%02d%02d%02d%02d%02d",
  48.         &ut.tm_year,
  49.         &ut.tm_mon,
  50.         &ut.tm_mday,
  51.         &ut.tm_hour,
  52.         &ut.tm_min,
  53.         &ut.tm_sec) == 6)
  54.     {    
  55.         --ut.tm_mon;
  56.         ut.tm_year -= 1900;
  57.         ut.tm_isdst = -1;
  58.         mt = mktime(&ut);
  59.         if (mt != (time_t) -1) {
  60.             mt += GetUTCOffset2(ut.tm_year, ut.tm_mon + 1, ut.tm_mday, ut.tm_hour, ut.tm_min);
  61.             result = (time_t) mt;
  62.         }
  63.     }
  64.     return result;
  65. #endif    /* HAVE_MKTIME */
  66. }    /* UnMDTMDate */
  67.