home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / compiler / clib / time.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-29  |  1.5 KB  |  80 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: time.c,v 1.1 1997/01/29 16:51:35 digulla Exp $
  4.  
  5.     Desc: Return the current time in seconds
  6.     Lang: english
  7. */
  8.  
  9. #include <dos/dos.h>
  10. #include <proto/dos.h>
  11.  
  12. long __gmtoffset;
  13.  
  14. /*****************************************************************************
  15.  
  16.     NAME */
  17. #include <time.h>
  18.  
  19.     time_t time (
  20.  
  21. /*  SYNOPSIS */
  22.     time_t * tloc)
  23.  
  24. /*  FUNCTION
  25.        time() returns the time since 00:00:00 GMT, January 1, 1970,
  26.        measured in seconds.
  27.  
  28.     INPUTS
  29.     tloc - If this pointer is non-NULL, then the time is written into
  30.         this variable as well.
  31.  
  32.     RESULT
  33.     The number of seconds.
  34.  
  35.     NOTES
  36.  
  37.     EXAMPLE
  38.     time_t tt1, tt2;
  39.  
  40.     // tt1 and tt2 are the same
  41.     tt1 = time (&tt2);
  42.  
  43.     // This is valid, too
  44.     tt1 = time (NULL);
  45.  
  46.     BUGS
  47.  
  48.     SEE ALSO
  49.     ctime(), asctime(), localtime()
  50.  
  51.     INTERNALS
  52.  
  53.     HISTORY
  54.     29.01.1997 digulla created
  55.  
  56. ******************************************************************************/
  57. {
  58.     struct DateStamp t;
  59.     time_t         tt;
  60.  
  61.     DateStamp (&t); /* Get timestamp */
  62.  
  63.     /*
  64.     2922 is the number of days between 1.1.1970 and 1.1.1978 (2 leap
  65.         years and 6 normal). The former number is the start value
  66.         for time(), the latter the start time for the AmigaOS
  67.         time functions.
  68.     1440 is the number of minutes per day
  69.     60 is the number of seconds per minute
  70.     */
  71.     tt = ((t.ds_Days + 2922) * 1440 + t.ds_Minute + __gmtoffset) * 60
  72.     + t.ds_Tick / TICKS_PER_SECOND;
  73.  
  74.     if (tloc != NULL)
  75.     *tloc = tt;
  76.  
  77.     return tt;
  78. } /* time */
  79.  
  80.