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

Diff for /src/usr.bin/touch/touch.c between version 1.14 and 1.15

version 1.14, 2006/03/08 12:20:05 version 1.15, 2007/05/25 13:56:59
Line 34 
Line 34 
 #include <sys/stat.h>  #include <sys/stat.h>
 #include <sys/time.h>  #include <sys/time.h>
   
   #include <ctype.h>
 #include <err.h>  #include <err.h>
 #include <errno.h>  #include <errno.h>
 #include <fcntl.h>  #include <fcntl.h>
Line 170 
Line 171 
 void  void
 stime_arg1(char *arg, struct timeval *tvp)  stime_arg1(char *arg, struct timeval *tvp)
 {  {
         struct tm       *t;          struct tm       *lt;
         time_t           tmptime;          time_t           tmptime;
         int              yearset;          int              yearset;
         char            *p;          char            *dot, *p;
                                         /* Start with the current time. */                                          /* Start with the current time. */
         tmptime = tvp[0].tv_sec;          tmptime = tvp[0].tv_sec;
         if ((t = localtime(&tmptime)) == NULL)          if ((lt = localtime(&tmptime)) == NULL)
                 err(1, "localtime");                  err(1, "localtime");
                                         /* [[CC]YY]MMDDhhmm[.SS] */                                          /* [[CC]YY]MMDDhhmm[.SS] */
         if ((p = strchr(arg, '.')) == NULL)          for (p = arg, dot = NULL; *p != '\0'; p++) {
                 t->tm_sec = 0;          /* Seconds defaults to 0. */                  if (*p == '.' && dot != NULL)
                           dot = p;
                   else if (!isdigit((unsigned char)*p))
                           goto terr;
           }
           if (dot == NULL)
                   lt->tm_sec = 0;         /* Seconds defaults to 0. */
         else {          else {
                 if (strlen(p + 1) != 2)                  *dot++ = '\0';
                   if (strlen(dot) != 2)
                         goto terr;                          goto terr;
                 *p++ = '\0';                  lt->tm_sec = ATOI2(dot);
                 t->tm_sec = ATOI2(p);                  if (lt->tm_sec > 61)    /* Could be leap second. */
                           goto terr;
         }          }
   
         yearset = 0;          yearset = 0;
         switch (strlen(arg)) {          switch (strlen(arg)) {
         case 12:                        /* CCYYMMDDhhmm */          case 12:                        /* CCYYMMDDhhmm */
                 t->tm_year = ATOI2(arg) * 100 - TM_YEAR_BASE;                  lt->tm_year = ATOI2(arg) * 100 - TM_YEAR_BASE;
                 yearset = 1;                  yearset = 1;
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case 10:                        /* YYMMDDhhmm */          case 10:                        /* YYMMDDhhmm */
                 if (yearset) {                  if (yearset) {
                         yearset = ATOI2(arg);                          yearset = ATOI2(arg);
                         t->tm_year += yearset;                          lt->tm_year += yearset;
                 } else {                  } else {
                         yearset = ATOI2(arg);                          yearset = ATOI2(arg);
                         if (yearset < 69)                          /* Preserve current century. */
                                 t->tm_year = yearset + 2000 - TM_YEAR_BASE;                          lt->tm_year = ((lt->tm_year / 100) * 100) + yearset;
                         else  
                                 t->tm_year = yearset + 1900 - TM_YEAR_BASE;  
                 }                  }
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case 8:                         /* MMDDhhmm */          case 8:                         /* MMDDhhmm */
                 t->tm_mon = ATOI2(arg);                  lt->tm_mon = ATOI2(arg);
                 --t->tm_mon;            /* Convert from 01-12 to 00-11 */                  if (lt->tm_mon > 12 || lt->tm_mon == 0)
                 t->tm_mday = ATOI2(arg);                          goto terr;
                 t->tm_hour = ATOI2(arg);                  --lt->tm_mon;           /* Convert from 01-12 to 00-11 */
                 t->tm_min = ATOI2(arg);                  lt->tm_mday = ATOI2(arg);
                   if (lt->tm_mday > 31 || lt->tm_mday == 0)
                           goto terr;
                   lt->tm_hour = ATOI2(arg);
                   if (lt->tm_hour > 23)
                           goto terr;
                   lt->tm_min = ATOI2(arg);
                   if (lt->tm_min > 59)
                           goto terr;
                 break;                  break;
         default:          default:
                 goto terr;                  goto terr;
         }          }
   
         t->tm_isdst = -1;               /* Figure out DST. */          lt->tm_isdst = -1;              /* Figure out DST. */
         tvp[0].tv_sec = tvp[1].tv_sec = mktime(t);          tvp[0].tv_sec = tvp[1].tv_sec = mktime(lt);
         if (tvp[0].tv_sec == -1)          if (tvp[0].tv_sec == -1)
 terr:           errx(1,  terr:           errx(1,
         "out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS]");          "out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS]");
Line 229 
Line 244 
 void  void
 stime_arg2(char *arg, int year, struct timeval *tvp)  stime_arg2(char *arg, int year, struct timeval *tvp)
 {  {
         struct tm       *t;          struct tm       *lt;
         time_t           tmptime;          time_t           tmptime;
                                         /* Start with the current time. */                                          /* Start with the current time. */
         tmptime = tvp[0].tv_sec;          tmptime = tvp[0].tv_sec;
         if ((t = localtime(&tmptime)) == NULL)          if ((lt = localtime(&tmptime)) == NULL)
                 err(1, "localtime");                  err(1, "localtime");
   
         t->tm_mon = ATOI2(arg);         /* MMDDhhmm[YY] */          lt->tm_mon = ATOI2(arg);        /* MMDDhhmm[YY] */
         --t->tm_mon;                    /* Convert from 01-12 to 00-11 */          if (lt->tm_mon > 12 || lt->tm_mon == 0)
         t->tm_mday = ATOI2(arg);                  goto terr;
         t->tm_hour = ATOI2(arg);          --lt->tm_mon;                   /* Convert from 01-12 to 00-11 */
         t->tm_min = ATOI2(arg);          lt->tm_mday = ATOI2(arg);
           if (lt->tm_mday > 31 || lt->tm_mday == 0)
                   goto terr;
           lt->tm_hour = ATOI2(arg);
           if (lt->tm_hour > 23)
                   goto terr;
           lt->tm_min = ATOI2(arg);
           if (lt->tm_min > 59)
                   goto terr;
         if (year) {          if (year) {
                 year = ATOI2(arg);                  year = ATOI2(arg);      /* Preserve current century. */
                 if (year < 69)                  lt->tm_year = ((lt->tm_year / 100) * 100) + year;
                         t->tm_year = year + 2000 - TM_YEAR_BASE;  
                 else  
                         t->tm_year = year + 1900 - TM_YEAR_BASE;  
         }          }
         t->tm_sec = 0;          lt->tm_sec = 0;
   
         t->tm_isdst = -1;               /* Figure out DST. */          lt->tm_isdst = -1;              /* Figure out DST. */
         tvp[0].tv_sec = tvp[1].tv_sec = mktime(t);          tvp[0].tv_sec = tvp[1].tv_sec = mktime(lt);
         if (tvp[0].tv_sec == -1)          if (tvp[0].tv_sec == -1)
                 errx(1,  terr:           errx(1,
         "out of range or illegal time specification: MMDDhhmm[YY]");          "out of range or illegal time specification: MMDDhhmm[YY]");
   
         tvp[0].tv_usec = tvp[1].tv_usec = 0;          tvp[0].tv_usec = tvp[1].tv_usec = 0;

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15