Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2017-01-20 05:45:16 +0300
committerCorinna Vinschen <corinna@vinschen.de>2017-01-20 12:30:47 +0300
commitca3e3bc54ee4a5a27fc7721a512818255c804812 (patch)
tree06a9f785db413438b0a631adfc6e25d26098327c /newlib/libc/locale
parentef007184874ead6f288e432eb23bfc76bf65929d (diff)
nl_langinfo: Add NL_LOCALE_NAME macro
Provide an extension NL_LOCALE_NAME() macro, with semantics matching glibc, which can be used as: nl_langinfo_l(NL_LOCALE_NAME(LC_MESSAGES), locale); to get back the locale string that locale was originally created with during newlocale(). This in turn allows a library (such as gettext) to determine what thread-local locale settings it has inherited from the main program without having to be told what parameters were passed to newlocale(), for less overall coupling between parts of the program. gnulib is set up to use the extension: https://lists.gnu.org/archive/html/bug-gnulib/2017-01/msg00129.html * libc/include/langinfo.h (NL_LOCALE_NAME): New macro * libc/locale/nl_langinfo.c (nl_langinfo_l): Expose locale names of a locale_t's category components. Signed-off-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'newlib/libc/locale')
-rw-r--r--newlib/libc/locale/nl_langinfo.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/newlib/libc/locale/nl_langinfo.c b/newlib/libc/locale/nl_langinfo.c
index 6d078b978..eb984912f 100644
--- a/newlib/libc/locale/nl_langinfo.c
+++ b/newlib/libc/locale/nl_langinfo.c
@@ -24,6 +24,8 @@
* SUCH DAMAGE.
*/
+#define _GNU_SOURCE
+
#include <sys/cdefs.h>
#include <locale.h>
@@ -368,6 +370,13 @@ do_codeset:
break;
#endif
default:
+ /* Relies on the fact that LC_ALL is 0, and all other
+ LC_ constants are in ascending order. */
+ if (item > NL_LOCALE_NAME(LC_ALL)
+ && item < NL_LOCALE_NAME(_LC_LAST)) {
+ return locale->categories[item
+ - NL_LOCALE_NAME(LC_ALL)];
+ }
#ifdef __HAVE_LOCALE_INFO_EXTENDED__
if (item > _NL_LOCALE_EXTENDED_FIRST_ENTRY
&& item < _NL_LOCALE_EXTENDED_LAST_ENTRY) {