fwp@unccvax.UUCP (02/17/87)
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. Do I have to 'execute' the workbench 'date' program? Also, what's the latest word on Manx 3.40 availability? Many thanks, Rick Pasotto
ali@navajo.UUCP (02/17/87)
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); }