1
/* nl_langinfo() replacement: query locale dependent information.
3
Copyright (C) 2007-2010 Free Software Foundation, Inc.
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 3 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program. If not, see <http://www.gnu.org/licenses/>. */
23
#if REPLACE_NL_LANGINFO
25
/* Override nl_langinfo with support for added nl_item values. */
33
rpl_nl_langinfo (nl_item item)
37
# if GNULIB_defined_CODESET
41
static char buf[2 + 10 + 1];
43
locale = setlocale (LC_CTYPE, NULL);
44
if (locale != NULL && locale[0] != '\0')
46
/* If the locale name contains an encoding after the dot, return
48
const char *dot = strchr (locale, '.');
55
/* Look for the possible @... trailer and remove it, if any. */
56
modifier = strchr (dot, '@');
59
if (modifier - dot < sizeof (buf))
61
memcpy (buf, dot, modifier - dot);
62
buf [modifier - dot] = '\0';
70
# if GNULIB_defined_T_FMT_AMPM
74
# if GNULIB_defined_ERA
76
/* The format is not standardized. In glibc it is a sequence of strings
77
of the form "direction:offset:start_date:end_date:era_name:era_format"
78
with an empty string at the end. */
81
/* The %Ex conversion in strftime behaves like %x if the locale does not
82
have an alternative time format. */
86
/* The %Ec conversion in strftime behaves like %c if the locale does not
87
have an alternative time format. */
91
/* The %EX conversion in strftime behaves like %X if the locale does not
92
have an alternative time format. */
96
/* The format is not standardized. In glibc it is a sequence of 10
97
strings, appended in memory. */
98
return "\0\0\0\0\0\0\0\0\0\0";
100
# if GNULIB_defined_YESEXPR
109
return nl_langinfo (item);
114
/* Provide nl_langinfo from scratch. */
116
# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
118
/* Native Windows platforms. */
120
# define WIN32_LEAN_AND_MEAN /* avoid including junk */
121
# include <windows.h>
127
/* An old Unix platform without locales, such as Linux libc5 or BeOS. */
134
nl_langinfo (nl_item item)
138
/* nl_langinfo items of the LC_CTYPE category */
140
# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
142
static char buf[2 + 10 + 1];
144
/* Woe32 has a function returning the locale's codepage as a number. */
145
sprintf (buf, "CP%u", GetACP ());
148
# elif defined __BEOS__
153
/* nl_langinfo items of the LC_NUMERIC category */
155
return localeconv () ->decimal_point;
157
return localeconv () ->thousands_sep;
158
/* nl_langinfo items of the LC_TIME category.
159
TODO: Really use the locale. */
162
return "%a %b %e %H:%M:%S %Y";
170
return "%I:%M:%S %p";
254
return "\0\0\0\0\0\0\0\0\0\0";
255
/* nl_langinfo items of the LC_MONETARY category
256
TODO: Really use the locale. */
259
/* nl_langinfo items of the LC_MESSAGES category
260
TODO: Really use the locale. */