From: Alan Cox Date: Fri, 31 Aug 2018 23:15:23 +0000 (+0100) Subject: setdate: polish and add a manual page X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=1db86d64d77adc0186b392f9bb4e9390a5c2166a;p=FUZIX.git setdate: polish and add a manual page --- diff --git a/Applications/util/setdate.8 b/Applications/util/setdate.8 new file mode 100644 index 00000000..dd2bdc80 --- /dev/null +++ b/Applications/util/setdate.8 @@ -0,0 +1,33 @@ +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 diff --git a/Applications/util/setdate.c b/Applications/util/setdate.c index 9fd82838..74e83105 100644 --- a/Applications/util/setdate.c +++ b/Applications/util/setdate.c @@ -1,3 +1,17 @@ +/* + * setdate: set time and date + */ + +#include +#include +#include +#include +#include +#include +#include + +static uint8_t utc; + /* * mktime.c -- converts a struct tm into a time_t * @@ -18,15 +32,6 @@ * Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include -#include -#include -#include -#include -#include -#include - 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, @@ -93,6 +98,9 @@ time_t mktime(struct tm *t) return(result); } +/* + * Fuzix real time clock reading and date setting + */ void unbc(uint8_t *p) { uint8_t c = *p & 0x0F; @@ -135,7 +143,7 @@ int rtcdate(void) 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) { @@ -150,7 +158,7 @@ int rtcdate(void) void usage(void) { - fprintf(stderr, "Usage: setdate [-a] [-u]\n"); + fprintf(stderr, "Usage: setdate [-a] [-u] [-0]\n"); exit(1); } @@ -164,7 +172,7 @@ int main(int argc, char *argv[]) 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; @@ -172,6 +180,9 @@ int main(int argc, char *argv[]) case 'u': user = 1; break; + case '0': + utc = 1; + break; default: usage(); } @@ -231,11 +242,11 @@ retime: } 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");