Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!mit-eddie!genrad!decvax!decwrl!labrea!navajo!ali From: ali@navajo.UUCP Newsgroups: comp.sys.amiga Subject: Re: Setting system date Message-ID: <1387@navajo.STANFORD.EDU> Date: Tue, 17-Feb-87 02:01:51 EST Article-I.D.: navajo.1387 Posted: Tue Feb 17 02:01:51 1987 Date-Received: Tue, 17-Feb-87 22:38:56 EST References: <628@unccvax.UUCP> Reply-To: ali@navajo.UUCP (Ali Ozer) Distribution: world Organization: Stanford University Lines: 73 Keywords: DateStamp In article <628@unccvax.UUCP> fwp@unccvax.UUCP (Rick Pasotto) writes: >How do I set the system date/time in a c program? DateStamp() only >returns the current date/time as do the manx time(c) functions. Here's a piece of code that will get/set the time using the IO device. It's mostly from the RKM, but the code in the version of the RKM I have was pretty buggy... The below works with Manx 3.20. #include "exec/types.h" #include "exec/nodes.h" #include "exec/lists.h" #include "exec/memory.h" #include "exec/interrupts.h" #include "exec/ports.h" #include "exec/libraries.h" #include "exec/tasks.h" #include "exec/io.h" #include "exec/devices.h" #include "devices/timer.h" #include "ctype.h" /* I'm not sure if you have to include all of the above, but, better safe than sorry... */ long OpenDevice (), DoIO (), CloseDevice (); struct timerequest tr; void TimerErr (closetimer) int closetimer; { if (closetimer != 0) CloseDevice (&tr); printf ("Timer Device Error.\n"); exit (1); } /* Returns the number of seconds since midnite Jan 1, 1978. */ long GetSysSeconds () { if (OpenDevice (TIMERNAME, UNIT_VBLANK, &tr, 0L) != 0L) TimerErr (0); tr.tr_node.io_Message.mn_Node.ln_Type = NT_MESSAGE; tr.tr_node.io_Message.mn_Node.ln_Pri = 0L; tr.tr_node.io_Message.mn_Node.ln_Name = NULL; tr.tr_node.io_Message.mn_ReplyPort = NULL; tr.tr_node.io_Command = TR_GETSYSTIME; if (DoIO (&tr) != 0L) TimerErr (1); CloseDevice (&tr); /* Do we care if this dies? Hmmm. No. */ return (tr.tr_time.tv_secs); } void SetSysSeconds (secs) long secs; { if (OpenDevice (TIMERNAME, UNIT_VBLANK, &tr, 0L) != 0L) TimerErr (0); tr.tr_node.io_Message.mn_Node.ln_Type = NT_MESSAGE; tr.tr_node.io_Message.mn_Node.ln_Pri = 0L; tr.tr_node.io_Message.mn_Node.ln_Name = NULL; tr.tr_node.io_Message.mn_ReplyPort = NULL; tr.tr_node.io_Command = TR_SETSYSTIME; tr.tr_time.tv_secs = secs; tr.tr_time.tv_micro = 0L; if (DoIO (&tr) != 0) TimerErr (1); CloseDevice (&tr); }