Print this page
2964 need POSIX 2008 locale object support
Reviewed by: Robert Mustacchi <rm@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libc/port/locale/regcomp.c
          +++ new/usr/src/lib/libc/port/locale/regcomp.c
   1    1  /*
        2 + * Copyright 2013 Garrett D'Amore <garrett@damore.org>
   2    3   * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
   3    4   * Copyright 2012 Milan Jurik. All rights reserved.
   4    5   * Copyright (c) 1992, 1993, 1994 Henry Spencer.
   5    6   * Copyright (c) 1992, 1993, 1994
   6    7   *      The Regents of the University of California.  All rights reserved.
   7    8   *
   8    9   * This code is derived from software contributed to Berkeley by
   9   10   * Henry Spencer.
  10   11   *
  11   12   * Redistribution and use in source and binary forms, with or without
↓ open down ↓ 706 lines elided ↑ open up ↑
 718  719  
 719  720  /*
 720  721   * p_b_term - parse one term of a bracketed character list
 721  722   */
 722  723  static void
 723  724  p_b_term(struct parse *p, cset *cs)
 724  725  {
 725  726          char c;
 726  727          wint_t start, finish;
 727  728          wint_t i;
      729 +        locale_t loc = uselocale(NULL);
 728  730  
 729  731          /* classify what we've got */
 730  732          switch ((MORE()) ? PEEK() : '\0') {
 731  733          case '[':
 732  734                  c = (MORE2()) ? PEEK2() : '\0';
 733  735                  break;
 734  736          case '-':
 735  737                  SETERROR(REG_ERANGE);
 736  738                  return;                 /* NOTE RETURN */
 737  739          default:
↓ open down ↓ 27 lines elided ↑ open up ↑
 765  767                          NEXT();
 766  768                          if (EAT('-'))
 767  769                                  finish = '-';
 768  770                          else
 769  771                                  finish = p_b_symbol(p);
 770  772                  } else
 771  773                          finish = start;
 772  774                  if (start == finish)
 773  775                          CHadd(p, cs, start);
 774  776                  else {
 775      -                        if (_collate_load_error) {
      777 +                        if (loc->collate->lc_is_posix) {
 776  778                                  (void) REQUIRE((uch)start <= (uch)finish,
 777  779                                      REG_ERANGE);
 778  780                                  CHaddrange(p, cs, start, finish);
 779  781                          } else {
 780  782                                  (void) REQUIRE(_collate_range_cmp(start,
 781      -                                    finish) <= 0, REG_ERANGE);
      783 +                                    finish, loc) <= 0, REG_ERANGE);
 782  784                                  for (i = 0; i <= UCHAR_MAX; i++) {
 783      -                                        if (_collate_range_cmp(start, i) <= 0 &&
 784      -                                            _collate_range_cmp(i, finish) <= 0)
      785 +                                        if (_collate_range_cmp(start, i, loc)
      786 +                                            <= 0 &&
      787 +                                            _collate_range_cmp(i, finish, loc)
      788 +                                            <= 0)
 785  789                                                  CHadd(p, cs, i);
 786  790                                  }
 787  791                          }
 788  792                  }
 789  793                  break;
 790  794          }
 791  795  }
 792  796  
 793  797  /*
 794  798   * p_b_cclass - parse a character-class name and deal with it
↓ open down ↓ 565 lines elided ↑ open up ↑
1360 1364          sop *scan;
1361 1365          sop *start;
1362 1366          sop *newstart;
1363 1367          sopno newlen;
1364 1368          sop s;
1365 1369          char *cp;
1366 1370          int offset;
1367 1371          char buf[MB_LEN_MAX];
1368 1372          size_t clen;
1369 1373          mbstate_t mbs;
     1374 +        locale_t loc = uselocale(NULL);
1370 1375  
1371 1376          /* avoid making error situations worse */
1372 1377          if (p->error != 0)
1373 1378                  return;
1374 1379  
1375 1380          /*
1376 1381           * It's not generally safe to do a ``char'' substring search on
1377 1382           * multibyte character strings, but it's safe for at least
1378 1383           * UTF-8 (see RFC 3629).
1379 1384           */
1380 1385          if (MB_CUR_MAX > 1 &&
1381      -            strcmp(_CurrentRuneLocale->__encoding, "UTF-8") != 0)
     1386 +            strcmp(loc->runelocale->__encoding, "UTF-8") != 0)
1382 1387                  return;
1383 1388  
1384 1389          /* find the longest OCHAR sequence in strip */
1385 1390          newlen = 0;
1386 1391          offset = 0;
1387 1392          g->moffset = 0;
1388 1393          scan = g->strip + 1;
1389 1394          do {
1390 1395                  s = *scan++;
1391 1396                  switch (OP(s)) {
↓ open down ↓ 365 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX