Print this page
3141 strptime() doesn't support %t

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libc/port/locale/strptime.c
          +++ new/usr/src/lib/libc/port/locale/strptime.c
   1    1  /*
        2 + * Copyright (c) 2014 Gary Mills
   2    3   * Copyright 2011, Nexenta Systems, Inc.  All rights reserved.
   3    4   * Copyright (c) 1994 Powerdog Industries.  All rights reserved.
   4    5   *
   5    6   * Redistribution and use in source and binary forms, with or without
   6    7   * modification, are permitted provided that the following conditions
   7    8   * are met:
   8    9   *
   9   10   * 1. Redistributions of source code must retain the above copyright
  10   11   *    notice, this list of conditions and the following disclaimer.
  11   12   *
↓ open down ↓ 196 lines elided ↑ open up ↑
 208  209                          if (c == 'M') {
 209  210                                  if (i > 59)
 210  211                                          return (NULL);
 211  212                                  tm->tm_min = i;
 212  213                          } else {
 213  214                                  if (i > 60)
 214  215                                          return (NULL);
 215  216                                  tm->tm_sec = i;
 216  217                          }
 217  218  
 218      -                        if (isspace(*buf))
 219      -                                while (*ptr != 0 && !isspace(*ptr))
 220      -                                        ptr++;
 221  219                          break;
 222  220  
 223  221                  case 'H':
 224  222                  case 'I':
 225  223                  case 'k':
 226  224                  case 'l':
 227  225                          /*
 228  226                           * Of these, %l is the only specifier explicitly
 229  227                           * documented as not being zero-padded.  However,
 230  228                           * there is no harm in allowing zero-padding.
↓ open down ↓ 11 lines elided ↑ open up ↑
 242  240                                  len--;
 243  241                          }
 244  242                          if (c == 'H' || c == 'k') {
 245  243                                  if (i > 23)
 246  244                                          return (NULL);
 247  245                          } else if (i > 12)
 248  246                                  return (NULL);
 249  247  
 250  248                          tm->tm_hour = i;
 251  249  
 252      -                        if (isspace(*buf))
 253      -                                while (*ptr != 0 && !isspace(*ptr))
 254      -                                        ptr++;
 255  250                          break;
 256  251  
 257  252                  case 'p':
 258  253                          /*
 259  254                           * XXX This is bogus if parsed before hour-related
 260  255                           * specifiers.
 261  256                           */
 262  257                          len = strlen(tptr->am);
 263  258                          if (strncasecmp(buf, tptr->am, len) == 0) {
 264  259                                  if (tm->tm_hour > 12)
↓ open down ↓ 47 lines elided ↑ open up ↑
 312  307  
 313  308                          len = 2;
 314  309                          for (i = 0; len && isdigit(*buf); buf++) {
 315  310                                  i *= 10;
 316  311                                  i += *buf - '0';
 317  312                                  len--;
 318  313                          }
 319  314                          if (i > 53)
 320  315                                  return (NULL);
 321  316  
 322      -                        if (isspace(*buf))
 323      -                                while (*ptr != 0 && !isspace(*ptr))
 324      -                                        ptr++;
 325  317                          break;
 326  318  
 327  319                  case 'w':
 328  320                          if (!isdigit(*buf))
 329  321                                  return (NULL);
 330  322  
 331  323                          i = *buf - '0';
 332  324                          if (i > 6)
 333  325                                  return (NULL);
 334  326  
 335  327                          tm->tm_wday = i;
 336  328  
 337      -                        if (isspace(*buf))
 338      -                                while (*ptr != 0 && !isspace(*ptr))
 339      -                                        ptr++;
 340  329                          break;
 341  330  
      331 +                case 'd':
 342  332                  case 'e':
 343  333                          /*
 344  334                           * The %e format has a space before single digits
 345  335                           * which we need to skip.
 346  336                           */
 347  337                          if (isspace(*buf))
 348  338                                  buf++;
 349      -                        /* FALLTHROUGH */
 350      -                case 'd':
 351  339                          /*
 352  340                           * The %e specifier is explicitly documented as not
 353  341                           * being zero-padded but there is no harm in allowing
 354  342                           * such padding.
 355  343                           *
 356  344                           * XXX The %e specifier may gobble one too many
 357  345                           * digits if used incorrectly.
 358  346                           */
 359  347                          if (!isdigit(*buf))
 360  348                                  return (NULL);
↓ open down ↓ 2 lines elided ↑ open up ↑
 363  351                          for (i = 0; len && isdigit(*buf); buf++) {
 364  352                                  i *= 10;
 365  353                                  i += *buf - '0';
 366  354                                  len--;
 367  355                          }
 368  356                          if (i > 31)
 369  357                                  return (NULL);
 370  358  
 371  359                          tm->tm_mday = i;
 372  360  
 373      -                        if (isspace(*buf))
 374      -                                while (*ptr != 0 && !isspace(*ptr))
 375      -                                        ptr++;
 376  361                          break;
 377  362  
 378  363                  case 'B':
 379  364                  case 'b':
 380  365                  case 'h':
 381  366                          for (i = 0; i < asizeof(tptr->month); i++) {
 382  367                                  len = strlen(tptr->month[i]);
 383  368                                  if (strncasecmp(buf, tptr->month[i], len) == 0)
 384  369                                          break;
 385  370                          }
↓ open down ↓ 24 lines elided ↑ open up ↑
 410  395                          for (i = 0; len && isdigit(*buf); buf++) {
 411  396                                  i *= 10;
 412  397                                  i += *buf - '0';
 413  398                                  len--;
 414  399                          }
 415  400                          if (i < 1 || i > 12)
 416  401                                  return (NULL);
 417  402  
 418  403                          tm->tm_mon = i - 1;
 419  404  
 420      -                        if (isspace(*buf))
 421      -                                while (*ptr != NULL && !isspace(*ptr))
 422      -                                        ptr++;
 423  405                          break;
 424  406  
 425  407                  case 's':
 426  408                          {
 427  409                          char *cp;
 428  410                          int sverrno;
 429  411                          time_t t;
 430  412  
 431  413                          sverrno = errno;
 432  414                          errno = 0;
↓ open down ↓ 25 lines elided ↑ open up ↑
 458  440                          }
 459  441                          if (c == 'Y')
 460  442                                  i -= 1900;
 461  443                          if (c == 'y' && i < 69)
 462  444                                  i += 100;
 463  445                          if (i < 0)
 464  446                                  return (NULL);
 465  447  
 466  448                          tm->tm_year = i;
 467  449  
 468      -                        if (isspace(*buf))
 469      -                                while (*ptr != 0 && !isspace(*ptr))
 470      -                                        ptr++;
 471  450                          break;
 472  451  
 473  452                  case 'Z':
 474  453                          {
 475  454                          const char *cp = buf;
 476  455                          char *zonestr;
 477  456  
 478  457                          while (isupper(*cp))
 479  458                                  ++cp;
 480  459                          if (cp - buf) {
↓ open down ↓ 33 lines elided ↑ open up ↑
 514  493                                  i *= 10;
 515  494                                  i += *buf - '0';
 516  495                                  buf++;
 517  496                          }
 518  497  
 519  498                          tm->tm_hour -= sign * (i / 100);
 520  499                          tm->tm_min -= sign * (i % 100);
 521  500                          *flagsp |= F_GMT;
 522  501                          }
 523  502                          break;
      503 +                case 'n':
      504 +                case 't':
      505 +                        while (isspace(*buf))
      506 +                                buf++;
      507 +                        break;
 524  508                  }
 525  509          }
 526  510  
 527  511          if (!recurse) {
 528  512                  if (buf && (*flagsp & F_GMT)) {
 529  513                          time_t t = timegm(tm);
 530  514                          (void) localtime_r(&t, tm);
 531  515                  }
 532  516          }
 533  517  
↓ open down ↓ 22 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX