Print this page
2964 need POSIX 2008 locale object support
   1 /*
   2  * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
   3  * Copyright (c) 2001, 2003 Alexey Zelkin <phantom@FreeBSD.org>
   4  * All rights reserved.
   5  *





   6  * Redistribution and use in source and binary forms, with or without
   7  * modification, are permitted provided that the following conditions
   8  * are met:
   9  * 1. Redistributions of source code must retain the above copyright
  10  *    notice, this list of conditions and the following disclaimer.
  11  * 2. Redistributions in binary form must reproduce the above copyright
  12  *    notice, this list of conditions and the following disclaimer in the
  13  *    documentation and/or other materials provided with the distribution.
  14  *
  15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25  * SUCH DAMAGE.
  26  */
  27 
  28 #include "lint.h"
  29 #include <langinfo.h>
  30 #include <limits.h>
  31 #include <locale.h>
  32 #include <stdlib.h>
  33 #include <string.h>
  34 
  35 #include "lnumeric.h"
  36 #include "lmessages.h"
  37 #include "lmonetary.h"
  38 #include "timelocal.h"
  39 
  40 #define _REL(BASE) ((int)item-BASE)
  41 
  42 #define MONETARY        (__get_current_monetary_locale())
  43 #define TIME            (__get_current_time_locale())
  44 #define MESSAGES        (__get_current_messages_locale())
  45 #define NUMERIC         (__get_current_numeric_locale())
  46 
  47 #pragma weak _nl_langinfo = nl_langinfo
  48 
  49 char *
  50 nl_langinfo(nl_item item)
  51 {
  52         char *ret, *s, *cs;
  53         static char *csym = NULL;
  54 
  55         switch (item) {
  56         case CODESET:
  57                 ret = "";
  58                 /*
  59                  * The codeset is the suffix of a locale, for most it will
  60                  * will be UTF-8, as in "en.UTF-8".  Short form locales are
  61                  * not supported.  Note also that although FreeBSD uses
  62                  * US-ASCII, Solaris historically has reported "646" for the
  63                  * C locale.
  64                  */
  65                 if ((s = setlocale(LC_CTYPE, NULL)) != NULL) {
  66                         if ((cs = strchr(s, '.')) != NULL)
  67                                 ret = cs + 1;
  68                         else if (strcmp(s, "C") == 0 || strcmp(s, "POSIX") == 0)
  69                                 ret = "646";
  70                 }


 177                                                 *csym = psn;
 178                                                 (void) strcpy(csym + 1, cs);
 179                                                 ret = csym;
 180                                         }
 181                                 }
 182                         }
 183                 }
 184                 break;
 185         case _DATE_FMT:         /* Solaris specific extension */
 186                 ret = (char *)TIME->date_fmt;
 187                 break;
 188         /*
 189          * Note that FreeBSD also had a private D_MD_ORDER, but that appears
 190          * to have been specific to FreeBSD, so we have not included it here.
 191          */
 192         default:
 193                 ret = "";
 194         }
 195         return (ret);
 196 }






   1 /*
   2  * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
   3  * Copyright (c) 2001, 2003 Alexey Zelkin <phantom@FreeBSD.org>
   4  * All rights reserved.
   5  *
   6  * Copyright (c) 2011 The FreeBSD Foundation
   7  * All rights reserved.
   8  * Portions of this software were developed by David Chisnall
   9  * under sponsorship from the FreeBSD Foundation.
  10  *
  11  * Redistribution and use in source and binary forms, with or without
  12  * modification, are permitted provided that the following conditions
  13  * are met:
  14  * 1. Redistributions of source code must retain the above copyright
  15  *    notice, this list of conditions and the following disclaimer.
  16  * 2. Redistributions in binary form must reproduce the above copyright
  17  *    notice, this list of conditions and the following disclaimer in the
  18  *    documentation and/or other materials provided with the distribution.
  19  *
  20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30  * SUCH DAMAGE.
  31  */
  32 
  33 #include "lint.h"
  34 #include <langinfo.h>
  35 #include <limits.h>
  36 #include <locale.h>
  37 #include <stdlib.h>
  38 #include <string.h>
  39 
  40 #include "lnumeric.h"
  41 #include "lmessages.h"
  42 #include "lmonetary.h"
  43 #include "timelocal.h"
  44 
  45 #define _REL(BASE) ((int)item-BASE)
  46 
  47 #define MONETARY        (__get_current_monetary_locale(loc))
  48 #define TIME            (__get_current_time_locale(loc))
  49 #define MESSAGES        (__get_current_messages_locale(loc))    /* XXX */
  50 #define NUMERIC         (__get_current_numeric_locale(loc))
  51 
  52 #pragma weak _nl_langinfo = nl_langinfo
  53 
  54 char *
  55 nl_langinfo_l(nl_item item, locale_t loc)
  56 {
  57         char *ret, *s, *cs;
  58         static char *csym = NULL;
  59 
  60         switch (item) {
  61         case CODESET:
  62                 ret = "";
  63                 /*
  64                  * The codeset is the suffix of a locale, for most it will
  65                  * will be UTF-8, as in "en.UTF-8".  Short form locales are
  66                  * not supported.  Note also that although FreeBSD uses
  67                  * US-ASCII, Solaris historically has reported "646" for the
  68                  * C locale.
  69                  */
  70                 if ((s = setlocale(LC_CTYPE, NULL)) != NULL) {
  71                         if ((cs = strchr(s, '.')) != NULL)
  72                                 ret = cs + 1;
  73                         else if (strcmp(s, "C") == 0 || strcmp(s, "POSIX") == 0)
  74                                 ret = "646";
  75                 }


 182                                                 *csym = psn;
 183                                                 (void) strcpy(csym + 1, cs);
 184                                                 ret = csym;
 185                                         }
 186                                 }
 187                         }
 188                 }
 189                 break;
 190         case _DATE_FMT:         /* Solaris specific extension */
 191                 ret = (char *)TIME->date_fmt;
 192                 break;
 193         /*
 194          * Note that FreeBSD also had a private D_MD_ORDER, but that appears
 195          * to have been specific to FreeBSD, so we have not included it here.
 196          */
 197         default:
 198                 ret = "";
 199         }
 200         return (ret);
 201 }
 202 
 203 char *
 204 nl_langinfo(nl_item item)
 205 {
 206         return (nl_langinfo_l(item, __get_locale()));
 207 }