home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / Programming / Python2 / Python20_source / Amiga / gettimeofday.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-25  |  3.2 KB  |  107 lines

  1. RCS_ID_C="$Id: gettimeofday.c,v 4.1 1994/09/29 23:09:02 jraja Exp $"
  2. /*
  3.  *      gettimeofday.c - get time of the day
  4.  *
  5.  *      Copyright © 1994 AmiTCP/IP Group, 
  6.  *                       Network Solutions Development Inc.
  7.  *                       All rights reserved.
  8.  */
  9.  
  10. #include <sys/param.h>
  11. #include <time.h>
  12. #include <sys/time.h>
  13.  
  14. #undef PROTO_TIMER_H
  15. #include <proto/timer.h>
  16.  
  17. /****** net.lib/gettimeofday *********************************************
  18.  
  19.     NAME   
  20.         gettimeofday - get date and time 
  21.  
  22.     SYNOPSIS
  23.         #include <sys/time.h>
  24.  
  25.         error = gettimeofday(tp, tzp)
  26.  
  27.         int gettimeofday(struct timeval *, struct timezone *)
  28.  
  29.     FUNCTION
  30.         The system's notion of the current Greenwich time and the
  31.         current time zone is obtained with the gettimeofday() call.
  32.         The time is expressed in seconds and microseconds since
  33.         midnight (0 hour), January 1, 1970.  The resolution of the
  34.         system clock is hardware dependent. If tzp is zero, the time
  35.         zone information will not be returned. Also, if your system
  36.         software is unable to provide time zone information, the
  37.         structure pointed by tzp will be filled with zeroes.
  38.    
  39.     PORTABILITY
  40.         UNIX
  41.  
  42.     INPUTS
  43.         The structures pointed to by tp and tzp are defined in
  44.         <sys/time.h> as:
  45.    
  46.              struct timeval {
  47.                   long tv_sec;      \* seconds since Jan. 1, 1970 *\
  48.                   long tv_usec;     \* and microseconds *\
  49.              };
  50.    
  51.              struct timezone {
  52.                   int  tz_minuteswest;   \* of Greenwich *\
  53.                   int  tz_dsttime;  \* type of dst correction to apply *\
  54.              };
  55.    
  56.         The timezone structure indicates the local time zone (meas-
  57.         ured in minutes of time westward from Greenwich), and a flag
  58.         that, if nonzero, indicates that Daylight Saving time
  59.         applies locally during the appropriate part of the year.
  60.  
  61.     RESULT
  62.         Returns 0 when successful and -1 with specific error code in 
  63.         errno in case of an error. No error codes are specified,
  64.         however.
  65.         
  66.     NOTES
  67.         gettimeofday() uses GetSysTime() function of the timer.device,
  68.         which is new to V36 of the device.
  69.  
  70.         Time zone information is taken from the locale.library, if it
  71.         is available (it is included in all Amiga systems from 2.1 and
  72.         up). Otherwise the environment variable "TZ" is consulted. If
  73.         it fails, the time zone is initialized to the GMT.
  74.  
  75.         Global variable TimerBase _must_ be initialized before
  76.         gettimeofday() is called. This is normally done automatically
  77.         by the autoinit module (timerinit.c) included in the net.lib.
  78.  
  79.     SEE ALSO
  80.         timer.device/GetSysTime()
  81. *****************************************************************************
  82. *
  83. */
  84.  
  85. /*
  86.  * See timerinit.c for comments on these
  87.  */
  88. extern struct timezone __time_zone;
  89. extern long __local_to_GMT;
  90.  
  91. int 
  92. gettimeofday(struct timeval *tp, struct timezone *tzp)
  93. {
  94.   if (tp) {
  95.     GetSysTime(tp);
  96.     tp->tv_sec += __local_to_GMT;
  97.   }
  98.   if (tzp) {
  99.     /*
  100.      * __time_zone is set up in the timerinit.c
  101.      */
  102.     *tzp = __time_zone;
  103.   }
  104.  
  105.   return 0;
  106. }
  107.