home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 1.ddi / CLIB1.ZIP / FTIME.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-07  |  2.7 KB  |  76 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. /*|                                                              |*/
  10. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  11. /*|                                                              |*/
  12. /*|                                                              |*/
  13. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  14. /*|     All Rights Reserved.                                     |*/
  15. /*|                                                              |*/
  16. /*[]------------------------------------------------------------[]*/
  17.  
  18.  
  19. #include <sys\timeb.h>
  20. #include <time.h>
  21. #include <dos.h>
  22. #include <mem.h>
  23. #include <_io.h>
  24.  
  25. /*---------------------------------------------------------------------*
  26.  
  27. Name        ftime - Get current time and store it in 'timeb' structure
  28.  
  29. Usage        void ftime(struct timeb *TimeStructPtr);
  30.  
  31. Prototype in    sys\timeb.h
  32.  
  33. Description    ftime determines the current time and fills in the fields
  34.         in the timeb structure pointed to by TimeStructPtr.
  35.  
  36. *---------------------------------------------------------------------*/
  37.  
  38. void ftime(struct timeb *TimeStructPtr)
  39. {
  40.     struct date DosDate, Vdate;
  41.     struct time DosTime;
  42.  
  43.     tzset(); /* Get timezone info. */
  44.  
  45.     /*
  46.        Because there is a window of vulnerability at exactly midnight when
  47.        calling getdate(INT 21 fn 2A) and gettime(INT 21 fn 2C) in succession,
  48.        we do 2 calls to getdate() to ensure we aren't in this window.
  49.     */
  50.     do
  51.     {
  52.         getdate(&DosDate);
  53.         gettime(&DosTime);
  54.         getdate(&Vdate);
  55.     }
  56.     while ( (DosDate.da_year != Vdate.da_year) ||
  57.                 (DosDate.da_day  != Vdate.da_day)  ||
  58.                 (DosDate.da_mon  != Vdate.da_mon) );
  59.  
  60.     /*
  61.        Convert extern 'timezone's seconds to structure 'timezone's minutes.
  62.        Set daylight savings indicator.
  63.        Convert DOS date and time to UNIX style time and store in structure.
  64.        Set milliseconds structure field. DOS is only accurate to 100ths of a
  65.           second so (100ths * 10) makes 1000ths.
  66.     */
  67.         TimeStructPtr->timezone = (short)(timezone / 60L);
  68.     if (daylight && __isDST( DosTime.ti_hour, DosDate.da_day,
  69.                                  DosDate.da_mon,  DosDate.da_year-1970) )
  70.         TimeStructPtr->dstflag  = 1;
  71.     else
  72.         TimeStructPtr->dstflag  = 0;
  73.     TimeStructPtr->time     = dostounix(&DosDate, &DosTime);
  74.     TimeStructPtr->millitm  = DosTime.ti_hund * 10;
  75. }
  76.