--- /dev/null
+#include <locale/langinfo.h>
--- /dev/null
+/* nl_langinfo -- Access to locale-dependent parameters.
+Copyright (C) 1995 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
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#ifndef _LANGINFO_H
+#define _LANGINFO_H 1
+
+#include <locale.h> /* Define the LC_* category names. */
+
+__BEGIN_DECLS
+
+/* Construct an `nl_item' value for `nl_langinfo' from a locale category
+ (LC_*) and an item index within the category. Some code may depend on
+ the item values within a category increasing monotonically with the
+ indices. */
+#define _NL_ITEM(category, index) (((category) << 16) | (index))
+
+/* Extract the category and item index from a constructed `nl_item' value. */
+#define _NL_ITEM_CATEGORY(item) ((int) (item) >> 16)
+#define _NL_ITEM_INDEX(item) ((int) (item) & 0xffff)
+
+
+/* Enumeration of locale items that can be queried with `nl_langinfo'. */
+typedef enum
+{
+ /* LC_TIME category: date and time formatting. */
+
+ /* Abbreviated days of the week. */
+ ABDAY_1 = _NL_ITEM (LC_TIME, 0), /* Sun */
+ ABDAY_2,
+ ABDAY_3,
+ ABDAY_4,
+ ABDAY_5,
+ ABDAY_6,
+ ABDAY_7,
+
+ /* Long-named days of the week. */
+ DAY_1, /* Sunday */
+ DAY_2, /* Monday */
+ DAY_3, /* Tuesday */
+ DAY_4, /* Wednesday */
+ DAY_5, /* Thursday */
+ DAY_6, /* Friday */
+ DAY_7, /* Saturday */
+
+ /* Abbreviated month names. */
+ ABMON_1, /* Jan */
+ ABMON_2,
+ ABMON_3,
+ ABMON_4,
+ ABMON_5,
+ ABMON_6,
+ ABMON_7,
+ ABMON_8,
+ ABMON_9,
+ ABMON_10,
+ ABMON_11,
+ ABMON_12,
+
+ /* Long month names. */
+ MON_1, /* January */
+ MON_2,
+ MON_3,
+ MON_4,
+ MON_5,
+ MON_6,
+ MON_7,
+ MON_8,
+ MON_9,
+ MON_10,
+ MON_11,
+ MON_12,
+
+ AM_STR, /* Ante meridian string. */
+ PM_STR, /* Post meridian string. */
+
+ D_T_FMT, /* Date and time format for strftime. */
+ D_FMT, /* Date format for strftime. */
+ T_FMT, /* Time format for strftime. */
+ T_FMT_AMPM, /* 12-hour time format for strftime. */
+
+ ERA, /* Alternate era. */
+ ERA_YEAR, /* Year in alternate era format. */
+ ERA_D_FMT, /* Date in alternate ear format. */
+ ALT_DIGITS, /* Alternate symbols for digits. */
+
+ _NL_NUM_LC_TIME, /* Number of indices in LC_TIME category. */
+
+ /* LC_CTYPE category: character classification.
+ This information is accessed by the functions in <ctype.h>.
+ These `nl_langinfo' names are used internally. */
+ _NL_CTYPE_CLASS_EB = _NL_ITEM (LC_CTYPE, 0),
+ _NL_CTYPE_TOUPPER_EB,
+ _NL_CTYPE_TOLOWER_EB,
+ _NL_CTYPE_CLASS_EL,
+ _NL_CTYPE_TOUPPER_EL,
+ _NL_CTYPE_TOLOWER_EL,
+ _NL_NUM_LC_CTYPE,
+
+ /* LC_MONETARY category: formatting of monetary quantities.
+ These items each correspond to a member of `struct lconv',
+ defined in <locale.h>. */
+ INT_CURR_SYMBOL = _NL_ITEM (LC_MONETARY, 0),
+ CURRENCY_SYMBOL,
+ MON_DECIMAL_POINT,
+ MON_THOUSANDS_SEP,
+ MON_GROUPING,
+ POSITIVE_SIGN,
+ NEGATIVE_SIGN,
+ INT_FRAC_DIGITS,
+ FRAC_DIGITS,
+ P_CS_PRECEDES,
+ P_SEP_BY_SPACE,
+ N_CS_PRECEDES,
+ N_SEP_BY_SPACE,
+ P_SIGN_POSN,
+ N_SIGN_POSN,
+ _NL_NUM_LC_MONETARY,
+
+ /* LC_NUMERIC category: formatting of numbers.
+ These also correspond to members of `struct lconv'; see <locale.h>. */
+ DECIMAL_POINT = _NL_ITEM (LC_NUMERIC, 0),
+ THOUSANDS_SEP,
+ GROUPING,
+ _NL_NUM_LC_NUMERIC,
+
+ YESEXPR = _NL_ITEM (LC_MESSAGES, 0), /* Regex matching ``yes'' input. */
+ NOEXPR, /* Regex matching ``no'' input. */
+ YESSTR, /* Output string for ``yes''. */
+ NOSTR, /* Output string for ``no''. */
+ _NL_NUM_LC_MESSAGES,
+
+ /* Stubs for unfinished categories. */
+ _NL_NUM_LC_COLLATE = 0,
+
+} nl_item;
+
+
+/* Return the current locale's value for ITEM.
+ If ITEM is invalid, an empty string is returned.
+
+ The string returned will not change until `setlocale' is called;
+ it is usually in read-only memory and cannot be modified. */
+
+extern char *nl_langinfo __P ((nl_item item));
+
+
+__END_DECLS
+
+#endif /* langinfo.h */
--- /dev/null
+/* Define current locale data for LC_CTYPE category.
+Copyright (C) 1995 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
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include "localeinfo.h"
+#include <ctype.h>
+#include <endian.h>
+
+_NL_CURRENT_DEFINE (LC_CTYPE);
+
+/* We are called after loading LC_CTYPE data to load it into
+ the variables used by the ctype.h macros.
+
+ There are three arrays of short ints which need to be indexable
+ from -128 to 255 inclusive. Stored in the locale data file are
+ a copy of each for each byte order. */
+
+void
+_nl_postload_ctype (void)
+{
+#if BYTE_ORDER == BIG_ENDIAN
+#define bo(x) x##_EB
+#elif BYTE_ORDER == LITTLE_ENDIAN
+#define bo(x) x##_EL
+#else
+#error bizarre byte order
+#endif
+
+#define current(unsigned,x) \
+ ((const unsigned short int *) _NL_CURRENT (LC_CTYPE, bo(_NL_CTYPE_##x)) \
+ + 128)
+
+ __ctype_b = current (unsigned, CLASS);
+ __ctype_toupper = current (, TOUPPER);
+ __ctype_tolower = current (, TOLOWER);
+}
--- /dev/null
+/* Define current locale data for LC_MESSAGES category.
+Copyright (C) 1995 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
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include "localeinfo.h"
+
+_NL_CURRENT_DEFINE (LC_MESSAGES);
--- /dev/null
+/* Define current locale data for LC_MONETARY category.
+Copyright (C) 1995 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
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include "localeinfo.h"
+
+_NL_CURRENT_DEFINE (LC_MONETARY);
--- /dev/null
+/* Define current locale data for LC_NUMERIC category.
+Copyright (C) 1995 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
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include "localeinfo.h"
+
+_NL_CURRENT_DEFINE (LC_NUMERIC);
--- /dev/null
+/* Define current locale data for LC_TIME category.
+Copyright (C) 1995 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
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include "localeinfo.h"
+
+_NL_CURRENT_DEFINE (LC_TIME);
--- /dev/null
+/* Functions to read locale data files.
+Copyright (C) 1995 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
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include "localeinfo.h"
+
+const size_t _nl_category_num_items[] =
+ {
+#define DEFINE_CATEGORY(category, category_name, items, a, b, c, d) \
+ [category] = _NL_NUM_##category,
+#include "categories.def"
+#undef DEFINE_CATEGORY
+ };
+
+struct locale_data *
+_nl_load_locale (int category, char **name)
+{
+ char *file;
+ int fd;
+ struct
+ {
+ unsigned int magic;
+ unsigned int nstrings;
+ unsigned int strindex[0];
+ } *filedata;
+ struct stat st;
+ struct locale_data *newdata;
+ int swap = 0;
+ inline unsigned int SWAP (const unsigned int *inw)
+ {
+ const unsigned char *inc = (const unsigned char *) inw;
+ if (!swap)
+ return *inw;
+ return (inc[3] << 24) | (inc[2] << 16) | (inc[1] << 8) | inc[0];
+ }
+ unsigned int i;
+
+ if ((*name)[0] == '\0')
+ {
+ *name = getenv (_nl_category_names[category]);
+ if (! *name || (*name) == '\0')
+ *name = getenv ("LANG");
+ if (! *name || (*name) == '\0')
+ *name = (char *) "local";
+ }
+
+/* XXX can't use asprintf here */
+ if (asprintf (&file, "%s%s/%s",
+ strchr (*name, '/') != NULL ? "" : "/share/locale/", /* XXX */
+ *name, _nl_category_names[category]) == -1)
+ return NULL;
+
+ fd = __open (file, O_RDONLY);
+ free (file);
+ if (fd < 0)
+ return NULL;
+ if (__fstat (fd, &st) < 0)
+ goto puntfd;
+
+ {
+ /* Map in the file's data. */
+ int save = errno;
+ filedata = (void *) __mmap ((caddr_t) 0, st.st_size,
+ PROT_READ, MAP_FILE|MAP_COPY, fd, 0);
+ if (filedata == (void *) -1)
+ {
+ if (errno == ENOSYS)
+ {
+ /* No mmap; allocate a buffer and read from the file. */
+ filedata = malloc (st.st_size);
+ if (filedata)
+ {
+ off_t to_read = st.st_size;
+ ssize_t nread;
+ char *p = (char *) filedata;
+ while (to_read > 0)
+ {
+ nread = __read (fd, p, to_read);
+ if (nread <= 0)
+ {
+ free (filedata);
+ if (nread == 0)
+ errno = EINVAL; /* Bizarreness going on. */
+ goto puntfd;
+ }
+ p += nread;
+ to_read -= nread;
+ }
+ }
+ else
+ goto puntfd;
+ errno = save;
+ }
+ else
+ goto puntfd;
+ }
+ }
+
+ if (filedata->magic == LIMAGIC (category))
+ /* Good data file in our byte order. */
+ swap = 0;
+ else
+ {
+ /* Try the other byte order. */
+ swap = 1;
+ if (SWAP (&filedata->magic) != LIMAGIC (category))
+ /* Bad data file in either byte order. */
+ {
+ puntmap:
+ __munmap ((caddr_t) filedata, st.st_size);
+ puntfd:
+ __close (fd);
+ return NULL;
+ }
+ }
+
+#define W(word) SWAP (&(word))
+
+ if (W (filedata->nstrings) < _nl_category_num_items[category] ||
+ (sizeof *filedata + W (filedata->nstrings) * sizeof (unsigned int)
+ >= st.st_size))
+ {
+ /* Insufficient data. */
+ errno = EINVAL;
+ goto puntmap;
+ }
+
+ newdata = malloc (sizeof *newdata +
+ W (filedata->nstrings) * sizeof (char *));
+ if (! newdata)
+ goto puntmap;
+
+ newdata->filedata = (void *) filedata;
+ newdata->filesize = st.st_size;
+ newdata->nstrings = W (filedata->nstrings);
+ for (i = 0; i < newdata->nstrings; ++i)
+ {
+ unsigned int idx = W (filedata->strindex[i]);
+ if (idx >= newdata->filesize)
+ {
+ free (newdata);
+ errno = EINVAL;
+ goto puntmap;
+ }
+ newdata->strings[i] = newdata->filedata + idx;
+ }
+
+ return newdata;
+}
+\f
+void
+_nl_free_locale (struct locale_data *data)
+{
+ int save = errno;
+ if (__munmap ((caddr_t) data->filedata, data->filesize) < 0)
+ {
+ if (errno == ENOSYS)
+ free ((void *) data->filedata);
+ errno = save;
+ }
+ free (data);
+}
+
--- /dev/null
+/* nl_langinfo -- User interface for extracting locale-dependent parameters.
+Copyright (C) 1995 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
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <langinfo.h>
+
+/* This array duplicates `_nl_current' defined in setlocale.c; but since
+ the references here are not weak references, this guarantees that the
+ data for all the categories will be linked in. */
+
+static const struct locale_data * *const nldata[] =
+{
+#define DEFINE_CATEGORY(category, category_name, items, a, b, c, d) \
+ [category] = &_nl_current_##category,
+#include "categories.def"
+#undef DEFINE_CATEGORY
+};
+
+
+/* Return a string with the data for locale-dependent parameter ITEM. */
+
+char *
+nl_langinfo (item)
+ nl_item item;
+{
+ int category = _NL_ITEM_CATEGORY (item);
+ unsigned int index = _NL_ITEM_INDEX (item);
+ const struct locale_data *data;
+
+ if (category < 0 || category >= LC_ALL)
+ {
+ /* Bogus category: bogus item. */
+ errno = EINVAL;
+ return NULL;
+ }
+
+ data = nldata[category];
+
+ if (index >= data->nstrings)
+ {
+ /* Bogus index for this category: bogus item. */
+ errno = EINVAL;
+ return NULL;
+ }
+
+ /* Return the string for the specified item. */
+ return (char *) nldata->strings[index];
+}