setdate: polish and add a manual page
authorAlan Cox <alan@linux.intel.com>
Fri, 31 Aug 2018 23:15:23 +0000 (00:15 +0100)
committerAlan Cox <alan@linux.intel.com>
Fri, 31 Aug 2018 23:15:23 +0000 (00:15 +0100)
Applications/util/setdate.8 [new file with mode: 0644]
Applications/util/setdate.c

diff --git a/Applications/util/setdate.8 b/Applications/util/setdate.8
new file mode 100644 (file)
index 0000000..dd2bdc8
--- /dev/null
@@ -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
index 9fd8283..74e8310 100644 (file)
@@ -1,3 +1,17 @@
+/*
+ *     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,
@@ -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");