Print this page
Fix compile errors, code review feedback, and add basic libc test suite.

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libc/port/locale/localeimpl.c
          +++ new/usr/src/lib/libc/port/locale/localeimpl.c
↓ open down ↓ 106 lines elided ↑ open up ↑
 107  107          },
 108  108          .ctype = &lc_ctype_posix,
 109  109          .numeric = &lc_numeric_posix,
 110  110          .collate = &lc_collate_posix,
 111  111          .monetary = &lc_monetary_posix,
 112  112          .messages = &lc_messages_posix,
 113  113          .time = &lc_time_posix,
 114  114          .runelocale = &_DefaultRuneLocale,
 115  115  };
 116  116  
 117      -locale_t __global_locale = &posix_locale;
      117 +locale_t ___global_locale = &posix_locale;
 118  118  
      119 +locale_t
      120 +__global_locale(void)
      121 +{
      122 +        return (___global_locale);
      123 +}
      124 +
 119  125  /*
 120  126   * Category names for getenv()  Note that this was modified
 121  127   * for Solaris.  See <iso/locale_iso.h>.
 122  128   */
 123  129  #define NUM_CATS        7
 124  130  static char *categories[7] = {
 125  131          "LC_CTYPE",
 126  132          "LC_NUMERIC",
 127  133          "LC_TIME",
 128  134          "LC_COLLATE",
↓ open down ↓ 260 lines elided ↑ open up ↑
 389  395  locale_t
 390  396  newlocale(int catmask, const char *locname, locale_t base)
 391  397  {
 392  398          locale_t loc;
 393  399          int i, e;
 394  400  
 395  401          if (catmask & ~(LC_ALL_MASK)) {
 396  402                  errno = EINVAL;
 397  403                  return (NULL);
 398  404          }
 399      -        loc = duplocale(base != NULL ? base : __global_locale);
      405 +        loc = duplocale(base != NULL ? base : ___global_locale);
 400  406          if (loc == NULL) {
 401  407                  return (NULL);
 402  408          }
 403  409  
 404  410          for (i = 0; i < LC_ALL; i++) {
 405  411                  struct locdata *ldata;
 406  412                  loc->loaded[i] = 0;
 407  413                  if (((1 << i) & catmask) == 0) {
 408  414                          /* Default to base locale if not overriding */
 409  415                          continue;
↓ open down ↓ 1 lines elided ↑ open up ↑
 411  417                  ldata = locdata_get(i, locname);
 412  418                  if (ldata == NULL) {
 413  419                          e = errno;
 414  420                          freelocale(loc);
 415  421                          errno = e;
 416  422                          return (NULL);
 417  423                  }
 418  424                  __locdata_release(loc->locdata[i]);
 419  425                  loc->locdata[i] = ldata;
 420  426          }
 421      -        if (base && base != __global_locale) {
      427 +        if (base && base != ___global_locale) {
 422  428                  freelocale(base);
 423  429          }
 424  430          loc->collate = loc->locdata[LC_COLLATE]->l_data[0];
 425  431          loc->ctype = loc->locdata[LC_CTYPE]->l_data[0];
 426  432          loc->runelocale = loc->locdata[LC_CTYPE]->l_data[1];
 427  433          loc->messages = loc->locdata[LC_MESSAGES]->l_data[0];
 428  434          loc->monetary = loc->locdata[LC_MONETARY]->l_data[0];
 429  435          loc->numeric = loc->locdata[LC_NUMERIC]->l_data[0];
 430  436          loc->time = loc->locdata[LC_TIME]->l_data[0];
 431  437          return (loc);
 432  438  }
 433  439  
 434  440  locale_t
 435  441  uselocale(locale_t loc)
 436  442  {
 437      -        locale_t lastloc = __global_locale;
      443 +        locale_t lastloc = ___global_locale;
 438  444          locale_t *locptr;
 439  445  
 440  446          locptr = tsdalloc(_T_SETLOCALE, sizeof (locale_t), freelocptr);
 441  447          /* Should never occur */
 442  448          if (locptr == NULL) {
 443  449                  errno = EINVAL;
 444  450                  return (NULL);
 445  451          }
 446  452  
 447  453          if (*locptr != NULL)
 448  454                  lastloc = *locptr;
 449  455  
 450  456          /* Argument loc is NULL if we are just querying. */
 451  457          if (loc != NULL) {
 452  458                  /*
 453  459                   * Set it to LC_GLOBAL_LOCAL to return to using
 454  460                   * the global locale (setlocale).
 455  461                   */
 456      -                if (loc == __global_locale) {
      462 +                if (loc == ___global_locale) {
 457  463                          *locptr = NULL;
 458  464                  } else {
 459  465                          /* No validation of the provided locale at present */
 460  466                          *locptr = loc;
 461  467                  }
 462  468          }
 463  469  
 464  470          /*
 465  471           * The caller is responsible for freeing, of course it would be
 466  472           * gross error to call freelocale() on a locale object that is still
 467  473           * in use.
 468  474           */
 469  475          return (lastloc);
 470  476  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX