[BACK]Return to util.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / chpass

Diff for /src/usr.bin/chpass/util.c between version 1.3 and 1.4

version 1.3, 1997/06/17 20:49:56 version 1.4, 1998/03/30 06:59:34
Line 56 
Line 56 
 #include "chpass.h"  #include "chpass.h"
 #include "pathnames.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",  
           "December", NULL };  
   
 char *  char *
 ttoa(tval)  ttoa(buf, len, tval)
           char *buf;
           size_t len;
         time_t tval;          time_t tval;
 {  {
         struct tm *tp;  
         static char tbuf[50];  
   
         if (tval) {          if (tval) {
                 tp = localtime(&tval);                  struct tm *tp = localtime(&tval);
                 (void)sprintf(tbuf, "%s %d, %d", months[tp->tm_mon],  
                     tp->tm_mday, tp->tm_year + TM_YEAR_BASE);                  (void) strftime(buf, len, "%B %d, %Y", tp);
                   buf[len - 1] = '\0';
         }          }
         else          else if (len > 0)
                 *tbuf = '\0';                  *buf = '\0';
         return (tbuf);          return (buf);
 }  }
   
 int  int
Line 86 
Line 79 
         time_t *store;          time_t *store;
 {  {
         static struct tm *lt;          static struct tm *lt;
         char *t, **mp;          struct tm tm;
           char *t;
         time_t tval;          time_t tval;
         int day, month, year;  
   
         if (!*p) {          if (!*p) {
                 *store = 0;                  *store = 0;
Line 99 
Line 92 
                 (void)time(&tval);                  (void)time(&tval);
                 lt = localtime(&tval);                  lt = localtime(&tval);
         }          }
         if (!(t = strtok(p, " \t")))          (void) memset(&tm, 0, sizeof(tm));
                 goto bad;          for (t = p; (t = strchr(t, ',')) != NULL; t++)
         for (mp = months;; ++mp) {                  *t = ' ';
                 if (!*mp)          t = strptime(p, "%B %d %Y", &tm);
                         goto bad;          if (t == NULL || (*t != '\0' && *t != '\n'))
                 if (!strncasecmp(*mp, t, 3)) {                  return 1;
                         month = mp - months + 1;          *store = mktime(&tm);
                         break;          if (*store == (time_t) -1)
                 }                  return 1;
         }  
         if (!(t = strtok(NULL, " \t,")) || !isdigit(*t))  
                 goto bad;  
         day = atoi(t);  
         if (!(t = strtok(NULL, " \t,")) || !isdigit(*t))  
                 goto bad;  
         year = atoi(t);  
         if (day < 1 || day > 31 || month < 1 || month > 12 || !year)  
                 goto bad;  
         if (year < 100)  
                 year += TM_YEAR_BASE;  
         if (year <= EPOCH_YEAR)  
 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;  
         *store = tval;  
         return (0);          return (0);
 }  }
   
Line 141 
Line 111 
         char *p, *sh;          char *p, *sh;
   
         setusershell();          setusershell();
         while (sh = getusershell()) {          while ((sh = getusershell()) != NULL) {
                 if (!strcmp(name, sh))                  if (!strcmp(name, sh))
                         return (name);                          return (name);
                 /* allow just shell name, but use "real" path */                  /* allow just shell name, but use "real" path */

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4