home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / xprzmodem_459.lzh / XprZmodem / getsystime.c < prev    next >
C/C++ Source or Header  |  1991-02-18  |  2KB  |  48 lines

  1. /* Amiga-type replacement for standard Unix time() function.  Can't use
  2.    Lattice's time() function from within a library because it's not
  3.    reentrant (has some hidden static vars it sets) and because it wants
  4.    you to have opened dos.library for some reason, which is supposedly
  5.    a bad idea inside a library.  Oh, well... this is quite a bit
  6.    smaller & faster anyway.  B-) */
  7.  
  8.  
  9. #include <proto/all.h>
  10. #include <exec/types.h>
  11. #include <exec/exec.h>
  12. #include <devices/timer.h>
  13. #include <string.h>
  14.  
  15. /* # seconds between 1-1-70 (Unix time base) and 1-1-78 (Amiga time base).
  16.    Add this value to the returned seconds count to convert Amiga system time
  17.    to normal Unix system time. */
  18. ULONG UnixTimeOffset = 252482400;
  19.  
  20.  
  21.  
  22. /* Returns current system time in standard Amiga-style timeval structure, if
  23.    you pass a pointer to one.  Also returns the seconds part as the return
  24.    value.  This lets you get just the seconds by calling GetSysTime(NULL)
  25.    if that's all you want, or the full timeval struct if you need that.
  26.    This is very similar to how the standard time() function is used. */
  27.  
  28. ULONG GetSysTime(struct timeval *tv) {
  29.   struct timerequest tr;
  30.  
  31.   /* timer.device must be working or the system would've died, so let's
  32.      not bother with error checking. */
  33.   memset(&tr,0,sizeof(tr));
  34.   OpenDevice(TIMERNAME,UNIT_VBLANK,(struct IORequest *)&tr,0L);
  35.  
  36.   tr.tr_node.io_Message.mn_Node.ln_Type = NT_MESSAGE;
  37.   tr.tr_node.io_Command = TR_GETSYSTIME;
  38.  
  39.   DoIO((struct IORequest *)&tr);
  40.  
  41.   if (tv)
  42.     *tv = tr.tr_time;
  43.  
  44.   CloseDevice((struct IORequest *)&tr);
  45.  
  46.   return tr.tr_time.tv_secs;
  47. }
  48.