|
Packit |
6c4009 |
/* User interface for extracting locale-dependent parameters.
|
|
Packit |
6c4009 |
Copyright (C) 1995-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <langinfo.h>
|
|
Packit |
6c4009 |
#include <locale.h>
|
|
Packit |
6c4009 |
#include <errno.h>
|
|
Packit |
6c4009 |
#include <stddef.h>
|
|
Packit |
6c4009 |
#include <stdlib.h>
|
|
Packit |
6c4009 |
#include "localeinfo.h"
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Return a string with the data for locale-dependent parameter ITEM. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
char *
|
|
Packit |
6c4009 |
__nl_langinfo_l (nl_item item, locale_t l)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
int category = _NL_ITEM_CATEGORY (item);
|
|
Packit |
6c4009 |
unsigned int index = _NL_ITEM_INDEX (item);
|
|
Packit |
6c4009 |
const struct __locale_data *data;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (category < 0 || category == LC_ALL || category >= __LC_LAST)
|
|
Packit |
6c4009 |
/* Bogus category: bogus item. */
|
|
Packit |
6c4009 |
return (char *) "";
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Special case value for NL_LOCALE_NAME (category).
|
|
Packit |
6c4009 |
This is not a real item index in the string table. */
|
|
Packit |
6c4009 |
if (index == _NL_ITEM_INDEX (_NL_LOCALE_NAME (category)))
|
|
Packit |
6c4009 |
return (char *) l->__names[category];
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#if defined NL_CURRENT_INDIRECT
|
|
Packit |
6c4009 |
/* Make direct reference to every _nl_current_CATEGORY symbol,
|
|
Packit |
6c4009 |
since we know only at runtime which categories are used. */
|
|
Packit |
6c4009 |
switch (category)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
# define DEFINE_CATEGORY(category, category_name, items, a) \
|
|
Packit |
6c4009 |
case category: data = *_nl_current_##category; break;
|
|
Packit |
6c4009 |
# include "categories.def"
|
|
Packit |
6c4009 |
# undef DEFINE_CATEGORY
|
|
Packit |
6c4009 |
default: /* Should be impossible. */
|
|
Packit |
6c4009 |
abort();
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
#else
|
|
Packit |
6c4009 |
data = l->__locales[category];
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (index >= data->nstrings)
|
|
Packit |
6c4009 |
/* Bogus index for this category: bogus item. */
|
|
Packit |
6c4009 |
return (char *) "";
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Return the string for the specified item. */
|
|
Packit |
6c4009 |
return (char *) data->values[index].string;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
libc_hidden_def (__nl_langinfo_l)
|
|
Packit |
6c4009 |
weak_alias (__nl_langinfo_l, nl_langinfo_l)
|