]> git.cameronkatri.com Git - pw-darwin.git/blobdiff - chpass/util.c
Add rcsid. Correct -Wall warning.
[pw-darwin.git] / chpass / util.c
index ec4cc1f7ddd45bc5c1dc7f1de173dac2dd9495b7..132c1514f99aaab3f2661e2de4636365bcbbb285 100644 (file)
  */
 
 #ifndef lint
+#if 0
 static char sccsid[] = "@(#)util.c     8.4 (Berkeley) 4/2/94";
+#endif
+static const char rcsid[] =
+       "$Id$";
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -43,14 +47,11 @@ static char sccsid[] = "@(#)util.c  8.4 (Berkeley) 4/2/94";
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
-#include <tzfile.h>
 #include <unistd.h>
 
 #include "chpass.h"
 #include "pathnames.h"
 
-static int dmsize[] =
-       { -1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
 static char *months[] =
        { "January", "February", "March", "April", "May", "June",
          "July", "August", "September", "October", "November",
@@ -66,12 +67,12 @@ ttoa(tval)
        if (tval) {
                tp = localtime(&tval);
                (void)sprintf(tbuf, "%s %d, %d", months[tp->tm_mon],
-                   tp->tm_mday, tp->tm_year + TM_YEAR_BASE);
+                   tp->tm_mday, tp->tm_year + 1900);
        }
        else
                *tbuf = '\0';
        return (tbuf);
-} 
+}
 
 int
 atot(p, store)
@@ -94,12 +95,16 @@ atot(p, store)
        }
        if (!(t = strtok(p, " \t")))
                goto bad;
-       for (mp = months;; ++mp) {
-               if (!*mp)
-                       goto bad;
-               if (!strncasecmp(*mp, t, 3)) {
-                       month = mp - months + 1;
-                       break;
+       if (isdigit(*t)) {
+               month = atoi(t);
+       } else {
+               for (mp = months;; ++mp) {
+                       if (!*mp)
+                               goto bad;
+                       if (!strncasecmp(*mp, t, 3)) {
+                               month = mp - months + 1;
+                               break;
+                       }
                }
        }
        if (!(t = strtok((char *)NULL, " \t,")) || !isdigit(*t))
@@ -111,18 +116,18 @@ atot(p, store)
        if (day < 1 || day > 31 || month < 1 || month > 12 || !year)
                goto bad;
        if (year < 100)
-               year += TM_YEAR_BASE;
-       if (year <= EPOCH_YEAR)
+               year += 1900;
+       if (year <= 1970)
 bad:           return (1);
-       tval = isleap(year) && month > 2;
-       for (--year; year >= EPOCH_YEAR; --year)
-               tval += isleap(year) ?
-                   DAYSPERLYEAR : DAYSPERNYEAR;
-       while (--month)
-               tval += dmsize[month];
-       tval += day;
-       tval = tval * HOURSPERDAY * MINSPERHOUR * SECSPERMIN;
-       tval -= lt->tm_gmtoff;
+       lt->tm_year = year - 1900;
+       lt->tm_mon = month - 1;
+       lt->tm_mday = day;
+       lt->tm_hour = 0;
+       lt->tm_min = 0;
+       lt->tm_sec = 0;
+       lt->tm_isdst = -1;
+       if ((tval = mktime(lt)) < 0)
+               return (1);
        *store = tval;
        return (0);
 }
@@ -134,7 +139,7 @@ ok_shell(name)
        char *p, *sh;
 
        setusershell();
-       while (sh = getusershell()) {
+       while ((sh = getusershell())) {
                if (!strcmp(name, sh))
                        return (name);
                /* allow just shell name, but use "real" path */