home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 5.ddi / CLIBSRC2.ZIP / FTIME.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  2.4 KB  |  78 lines

  1. /*------------------------------------------------------------------------
  2.  * filename - ftime.c
  3.  *
  4.  * function(s)
  5.  *        ftime - Get current time and store it in 'timeb' structure
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1987, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #include <sys\timeb.h>
  18. #include <time.h>
  19. #include <dos.h>
  20. #include <mem.h>
  21. #include <_io.h>
  22.  
  23. /*---------------------------------------------------------------------*
  24.  
  25. Name            ftime - Get current time and store it in 'timeb' structure
  26.  
  27. Usage           void ftime(struct timeb *TimeStructPtr);
  28.  
  29. Prototype in    sys\timeb.h
  30.  
  31. Description     ftime determines the current time and fills in the fields
  32.                 in the timeb structure pointed to by TimeStructPtr.
  33.  
  34. *---------------------------------------------------------------------*/
  35.  
  36. void _FARFUNC ftime(struct timeb _FAR *TimeStructPtr)
  37. {
  38.     struct date DosDate, Vdate;
  39.     struct time DosTime;
  40.  
  41.     tzset(); /* Get timezone info. */
  42.  
  43.     /*
  44.        Because there is a window of vulnerability at exactly midnight when
  45.        calling getdate(INT 21 fn 2A) and gettime(INT 21 fn 2C) in succession,
  46.        we do 2 calls to getdate() to ensure we aren't in this window.
  47.     */
  48.     do
  49.     {
  50.         getdate(&DosDate);
  51.         gettime(&DosTime);
  52.         getdate(&Vdate);
  53.     }
  54.     while ( (DosDate.da_year != Vdate.da_year) ||
  55.                 (DosDate.da_day  != Vdate.da_day)  ||
  56.                 (DosDate.da_mon  != Vdate.da_mon) );
  57.  
  58.     /*
  59.        Convert extern 'timezone's seconds to structure 'timezone's minutes.
  60.        Set daylight savings indicator.
  61.        Convert DOS date and time to UNIX style time and store in structure.
  62.        Set milliseconds structure field. DOS is only accurate to 100ths of a
  63.           second so (100ths * 10) makes 1000ths.
  64.     */
  65. #if defined(_RTLDLL)
  66.         TimeStructPtr->_timezone = (short)(timezone / 60L);
  67. #else
  68.         TimeStructPtr->timezone = (short)(timezone / 60L);
  69. #endif
  70.     if (daylight && __isDST( DosTime.ti_hour, DosDate.da_day,
  71.                                  DosDate.da_mon,  DosDate.da_year-1970) )
  72.         TimeStructPtr->dstflag  = 1;
  73.     else
  74.         TimeStructPtr->dstflag  = 0;
  75.     TimeStructPtr->time     = dostounix(&DosDate, &DosTime);
  76.     TimeStructPtr->millitm  = DosTime.ti_hund * 10;
  77. }
  78.