/* User interface for extracting locale-dependent parameters.
- Copyright (C) 1995-1997,1999-2002,2005,2007,2010 Free Software Foundation, Inc.
+ Copyright (C) 1995-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
+ <https://www.gnu.org/licenses/>. */
#include <langinfo.h>
#include <locale.h>
#include <errno.h>
#include <stddef.h>
+#include <stdlib.h>
#include "localeinfo.h"
/* Return a string with the data for locale-dependent parameter ITEM. */
char *
-__nl_langinfo_l (item, l)
- nl_item item;
- __locale_t l;
+__nl_langinfo_l (nl_item item, locale_t l)
{
int category = _NL_ITEM_CATEGORY (item);
unsigned int index = _NL_ITEM_INDEX (item);
if (index == _NL_ITEM_INDEX (_NL_LOCALE_NAME (category)))
return (char *) l->__names[category];
+#if defined NL_CURRENT_INDIRECT
+ /* Make direct reference to every _nl_current_CATEGORY symbol,
+ since we know only at runtime which categories are used. */
+ switch (category)
+ {
+# define DEFINE_CATEGORY(category, category_name, items, a) \
+ case category: data = *_nl_current_##category; break;
+# include "categories.def"
+# undef DEFINE_CATEGORY
+ default: /* Should be impossible. */
+ abort();
+ }
+#else
data = l->__locales[category];
+#endif
if (index >= data->nstrings)
/* Bogus index for this category: bogus item. */