--- /dev/null
+SETDATE(8)
+## NAME
+*setdate* - set the system time and date
+## SYNOPSIS
+*setdate* \[OPTIONS\]
+##DESCRIPTION
+*Setdate* sets the system time and date either by prompting the user or if
+available it can read from the /dev/rtc device and set the time based upon
+that.
+## OPTIONS
+:*-a*
+ Set the time from the real time clock if present and never prompt the user
+
+:*-u*
+ Prompt for the time from the user even if a real time clock is present
+
+:*-0*
+ Assume that times are in UTC not local time.
+
+When the -0 option is not used the time zone is taken from the TZ
+environment variable. The time will be computed based upon the specified
+local time including daylight savings.
+## STANDARDS
+This is a Fuzix specific command loosely modelled on the traditional DOS
+interface.
+## EXIT STATUS
+*setdate* returns 0 on success, 1 if it could not set the time as there is
+no RTC, 2 if there were insufficient permissions and 127 in
+the case of an internal error.
+## SEE ALSO
+*date*(1), *rtc*(4).
+## AUTHOR
+Alan Cox
+/*
+ * setdate: set time and date
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <time.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/rtc.h>
+
+static uint8_t utc;
+
/*
* mktime.c -- converts a struct tm into a time_t
*
* Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <time.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/rtc.h>
-
static uint8_t dim[13] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
static char day[] = {
'S','u','n',0,
return(result);
}
+/*
+ * Fuzix real time clock reading and date setting
+ */
void unbc(uint8_t *p)
{
uint8_t c = *p & 0x0F;
tm.tm_hour = *p++;
tm.tm_min = *p++;
tm.tm_sec = *p;
- tm.tm_isdst = 0; /* FIXME -1 once we have dst fixed */
+ tm.tm_isdst = utc ? 0 : -1;
rtc.data.clock = mktime(&tm);
case CMOS_RTC_TIME:
if (stime(&rtc.data.clock) == -1) {
void usage(void)
{
- fprintf(stderr, "Usage: setdate [-a] [-u]\n");
+ fprintf(stderr, "Usage: setdate [-a] [-u] [-0]\n");
exit(1);
}
int opt;
int user = 0, autom = 0;
- while ((opt = getopt(argc, argv, "au")) != -1) {
+ while ((opt = getopt(argc, argv, "au0")) != -1) {
switch(opt) {
case 'a':
autom = 1;
case 'u':
user = 1;
break;
+ case '0':
+ utc = 1;
+ break;
default:
usage();
}
}
if (!set)
return 0;
- tm->tm_isdst = 0; /* FIXME -1 once we have dst fixed */
+ tm->tm_isdst = utc ? 0 : -1;
t = mktime(tm);
if (t == (time_t) -1) {
fprintf(stderr, "mktime: internal error.\n");
- return 255;
+ return 127;
}
if (stime(&t)) {
perror("stime");