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

Diff for /src/usr.bin/ts/ts.c between version 1.7 and 1.8

version 1.7, 2022/07/06 07:59:03 version 1.8, 2022/07/07 10:40:25
Line 31 
Line 31 
 static char             *buf;  static char             *buf;
 static char             *outbuf;  static char             *outbuf;
 static size_t            bufsize;  static size_t            bufsize;
   static size_t            obsize;
   
 static void              fmtfmt(const struct timespec *);  static void              fmtfmt(const struct timespec *);
 static void __dead       usage(void);  static void __dead       usage(void);
Line 77 
Line 78 
         if (argc == 1)          if (argc == 1)
                 format = *argv;                  format = *argv;
   
         bufsize = strlen(format);          bufsize = strlen(format) + 1;
         if (bufsize > SIZE_MAX / 10)          if (bufsize > SIZE_MAX / 10)
                 errx(1, "format string too big");                  errx(1, "format string too big");
   
         bufsize *= 10;          bufsize *= 10;
           obsize = bufsize;
         if ((buf = calloc(1, bufsize)) == NULL)          if ((buf = calloc(1, bufsize)) == NULL)
                 err(1, NULL);                  err(1, NULL);
         if ((outbuf = calloc(1, bufsize)) == NULL)          if ((outbuf = calloc(1, obsize)) == NULL)
                 err(1, NULL);                  err(1, NULL);
   
         /* force UTC for interval calculations */          /* force UTC for interval calculations */
Line 165 
Line 166 
                 }                  }
         } while (*f != '\0');          } while (*f != '\0');
   
         if (strftime(outbuf, bufsize, buf, tm) == 0)          *outbuf = '\0';
                 errx(1, "strftime");          if (*buf != '\0') {
                   while (strftime(outbuf, obsize, buf, tm) == 0) {
                           if ((outbuf = reallocarray(outbuf, 2, obsize)) == NULL)
                                   err(1, NULL);
                           obsize *= 2;
                   }
           }
         fprintf(stdout, "%s ", outbuf);          fprintf(stdout, "%s ", outbuf);
         if (ferror(stdout))          if (ferror(stdout))
                 exit(1);                  exit(1);

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8