mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-18 19:10:06 +00:00
c4563d2d66
1999-04-28 Ulrich Drepper <drepper@cygnus.com> * argp/argp-ba.c (argp_program_bug_address): Don't initialize with 0. * argp/argp-parse.c (_argp_hang): Likewise. * argp/argp-pv.c (argp_program_version): Likewise. * argp/argp-pvh.c (argp_program_version_hook): Likewise. * inet/ether_hton.c (ether_hton, startp): Likewise. * inet/ether_ntoh.c (ether_ntoh, startp): Likewise. * inet/getnetgrent_r.c (setup, startp): Likewise. * intl/loadmsgcat.c (_nl_msg_cat_cntr): Likewise. * intl/localealias.c (string_space, string_space_act, string_space_max, nmap, maxmap): Likewise. * libio/iopopen.c (proc_file_chain): Likewise. * libio/oldiopopen.c (old_proc_file_chain): Likewise. * locale/lc-collate.c (__collate_table, __collate_extra, __collate_element_hash, __collate_element_strings, __collate_element_values): Likewise. * malloc/mcheck.c (mcheck_used): Likewise. * malloc/mtrace.c (added_atexit_handler): Likewise. * malloc/set-freeres.c (already_called): Likewise. * misc/getpass.c (getpass) [buf, bufsize]: Likewise. * misc/syslog.c (LogStat, LogTag): Likewise. * nss/XXX-lookup.c (DATABASE_NAME_SYMBOL): Likewise. * nss/getXXbyYY_r.c (startp): Likewise. * posix/getopt.c (optarg, __getopt_initialized): Likewise. * posix/regex.c (init_syntax_once) [done]: Likewise. (debug): Likewise. * string/strfry.c (init): Likewise. * sunrpc/svc_run.c (svc_top): Likewise. * posix/euidaccess.c (have_ids): Likewise. * sysdeps/unix/sysv/linux/poll.c (must_emulate): Likewise. * sysdeps/unix/sysv/linux/ttyname.c (__ttyname, namelen): Likewise. * time/getdate.c (getdate_err): Likewise. * time/tzfile.c (transitions, type_idxs, types, zone_names, leaps): Likewise. * time/tzset.c (old_tz, is_initialized): Likewise. * inet/getnameinfo.c (nrl_domainname): Rewrite to allow initialization of static data with zero. * signal/allocrtsig.c (init): Likewise. * string/Makefile (routines): Add strchrnul. * string/Versions [GLIBC_2.1.1]: Add strchrnul. * string/string.c: Add strchrnul prototype. * include/string.h: Add __strchrnul prototype. * sysdeps/generic/strchrnul.c: New file. * sysdeps/i386/strchrnul.S: New file. * sysdeps/i386/bits/string.c: Add strchrnul optimization. * sysdeps/i386/i486/bits/string.c: Likewise. * argp/argp-help.c (argp_args_usage): Use __strchrnul. * inet/ether_line.c (ether_line): Likewise. * nscd/nscd_conf.c (nscd_parse_file): Likewise. * nss/nsswitch.c (nss_parse_file): Likewise. * posix/execvp.c (execvp): Likewise. * posix/fnmatch.c (internal_fnmatch): Likewise. * resolv/res_hconf.c (_res_hconv_init): Likewise. * resolv/res_init.c (res_init): Likewise. * stdlib/fmtmsg.c (init): Likewise. * stdlib/getsubopt.c (getsubopt): Likewise. * catgets/catgets.c (catopen): Only allocate one memory block. (catclose): Only one free call necessary. * catgets/open_catalog.c (__open_catalog): Simplify handling of file descriptor. * ctype/ctype-extn.c: Make __toascii_l and __isascii_l alias instead of real functions. Simplify _tolower and _toupper. * grp/initgroups.c (compat_call): Remove unnecessary use of pointer variable. * iconv/gconv.h (struct gconv_info): Change data element from pointer to array of size 0. * iconv/gconv_open.c (__gconv_open): Allocate structures accordingly. * iconv/gconv_close.c (__gconv_close): Don't free data. * iconv/gconv_conf.c (add_alias): Avoid searching in tree twice to insert new alias. * iconv/gconv_db.c (add_derivation): More efficient copying. Check for error while inserting in tree. * include/time.h: Pretty print. * inet/ruserpass.c: Rewrite use of toktab to avoid string pointers in table and lots of relocations. * posix/regex.c (regerror): Rewrite use of re_error_msgid to avoid string pointers in table and lots of relocations. * intl/finddomain.c: Remove definition of strchr macro. * io/ftw.c (nftw_arr, ftw_arr): Make const. * locale/loadlocale.c (_nl_load_locale): Optimize string copying. * locale/localeinfo.h (_nl_category_names): Change into an array with fixed width char string elements. * locale/setlocale.c (_nl_category_names): Likewise. (_nl_current): Make global. * locale/nl_langinfo.c (nldata): Removed. Use _nl_current now. * malloc/Makefile (distribute): Add stackinfo.h. * sysdeps/generic/stackinfo.h: New file. * sysdeps/i386/stackinfo.h: New file. * posix/execl.c: Use stackinfo.h in optimizing alloca use. * posix/execle.c: Likewise. * posix/execlp.c: Likewise. * nis/nis_table.c (__create_ib_request): Always use realloc. * posix/execvp.c (execute): Rename to script_execute and keep only code to execute using shell. (execvp): Call execv directly and only fall back on script_execute. * resolv/inet_net_pton.c (inet_net_pton_ipv4): Remove digits define and always use xdigits instead. * resolv/res_init.c (res_init): Use rawmemchr instead of strchr where appropriate. * stdlib/fpioconst.h (__tens): New declaration. (struct mp_power): Remove array, add arrayoff element. * stdlib/fpioconst.c: Replace definitions of _ten_p* arrays by one __tens array and add in _fpioconst_pow10 offsets into __tens. * stdio-common/printf_fp.c: Rewrite to use new __tens array. * stdlib/strtod.c: Likewise. * stdlib/a64l.c (a64l_table): Avoid unnecessary elements. * stdlib/exit.c: Rewrite to use __exit_funcs being as sign for end of the list. * stdlib/atexit.c (__exit_funcs): Don't initialize. * stdlib/fmtmsg.c (keywords): Make name element fixed width array. * sunrpc/clnt_perr.c: Rewrite clnt_sperrno and auth_errmsg to use a single and an array with offsets. * sunrpc/des_soft.c (partab): Make it const. * sunrpc/key_call.c (trytimeout, tottimeout): Make const. (__key_encryptsession_pk_LOCAL): Don't initialize with 0. (__key_decryptsession_pk_LOCAL): Likewise. (__key_gendes_LOCAL): Likewise. (MESSENGER): Mark const. (key_call_private_main): Don't initialize with 0. (use_keyenvoy): Don't initialize with 0. (key_call): Rewrite to reverse logic of use_doors variable. * sunrpc/netname.c (OPSYS): Define as array, not pointer. (startp): Don't initialize with zero. * sunrpc/openchild.c (_openchild): Make first argument const. * sunrpc/pmap_rmt.c (timeout): Mark const. * sunrpc/xcrypt.c (hex): Likewise. * sysdeps/unix/sysv/linux/getcwd.c: Rewrite to allow omitting initialization of global variables. * sysdeps/unix/sysv/linux/getpt.c: Likewise. * sysdeps/unix/sysv/linux/if_index.c: Likewise. * termios/tcgetsid.c: Likewise. * sysdeps/unix/sysv/linux/i386/dl-procinfo.h (x86_cap_flags): Change fxsr to osfxsr. * time/tzfile.c (__tzfile_read): Rewrite to allocate only one memory block. Add function to free memory if wanted. * time/tzset.c (tzset_internal): Pass extra argument to __tzfile_read. * wcsmbs/wcsmbsload.c (to_wc, to_mb): Correct initializers. * wcsmbs/wmemset.c: Little code optimization.
261 lines
6.6 KiB
C
261 lines
6.6 KiB
C
/* Functions to read locale data files.
|
|
Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
Contributed by Ulrich Drepper <drepper@gnu.org>, 1996.
|
|
|
|
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., 59 Temple Place - Suite 330,
|
|
Boston, MA 02111-1307, USA. */
|
|
|
|
#include <errno.h>
|
|
#include <fcntl.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#ifdef _POSIX_MAPPED_FILES
|
|
# include <sys/mman.h>
|
|
#endif
|
|
#include <sys/stat.h>
|
|
|
|
#include "localeinfo.h"
|
|
|
|
|
|
static const size_t _nl_category_num_items[] =
|
|
{
|
|
#define DEFINE_CATEGORY(category, category_name, items, a, b, c, d) \
|
|
[category] = _NL_ITEM_INDEX (_NL_NUM_##category),
|
|
#include "categories.def"
|
|
#undef DEFINE_CATEGORY
|
|
};
|
|
|
|
|
|
#define NO_PAREN(arg, rest...) arg, ##rest
|
|
|
|
#define DEFINE_CATEGORY(category, category_name, items, a, b, c, d) \
|
|
static const enum value_type _nl_value_type_##category[] = { NO_PAREN items };
|
|
#define DEFINE_ELEMENT(element, element_name, optstd, type, rest...) \
|
|
[_NL_ITEM_INDEX (element)] = type,
|
|
#include "categories.def"
|
|
#undef DEFINE_CATEGORY
|
|
|
|
static const enum value_type *_nl_value_types[] =
|
|
{
|
|
#define DEFINE_CATEGORY(category, category_name, items, a, b, c, d) \
|
|
[category] = _nl_value_type_##category,
|
|
#include "categories.def"
|
|
#undef DEFINE_CATEGORY
|
|
};
|
|
|
|
|
|
void
|
|
_nl_load_locale (struct loaded_l10nfile *file, int category)
|
|
{
|
|
int fd;
|
|
struct
|
|
{
|
|
unsigned int magic;
|
|
unsigned int nstrings;
|
|
unsigned int strindex[0];
|
|
} *filedata;
|
|
struct stat st;
|
|
struct locale_data *newdata;
|
|
int save_err;
|
|
int swap = 0;
|
|
int mmaped = 1;
|
|
size_t cnt;
|
|
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];
|
|
}
|
|
|
|
file->decided = 1;
|
|
file->data = NULL;
|
|
|
|
fd = __open (file->filename, O_RDONLY);
|
|
if (fd < 0)
|
|
/* Cannot open the file. */
|
|
return;
|
|
|
|
if (__fstat (fd, &st) < 0)
|
|
goto puntfd;
|
|
if (S_ISDIR (st.st_mode))
|
|
{
|
|
/* LOCALE/LC_foo is a directory; open LOCALE/LC_foo/SYS_LC_foo
|
|
instead. */
|
|
char *newp;
|
|
size_t filenamelen;
|
|
|
|
__close (fd);
|
|
|
|
filenamelen = strlen (file->filename);
|
|
newp = (char *) alloca (filenamelen
|
|
+ 5 + _nl_category_name_sizes[category] + 1);
|
|
__mempcpy (__mempcpy (__mempcpy (newp, file->filename, filenamelen),
|
|
"/SYS_", 5),
|
|
_nl_category_names[category],
|
|
_nl_category_name_sizes[category] + 1);
|
|
|
|
fd = __open (newp, O_RDONLY);
|
|
if (fd < 0)
|
|
return;
|
|
|
|
if (__fstat (fd, &st) < 0)
|
|
goto puntfd;
|
|
}
|
|
|
|
/* Map in the file's data. */
|
|
save_err = errno;
|
|
#ifdef _POSIX_MAPPED_FILES
|
|
# ifndef MAP_COPY
|
|
/* Linux seems to lack read-only copy-on-write. */
|
|
# define MAP_COPY MAP_PRIVATE
|
|
# endif
|
|
# ifndef MAP_FILE
|
|
/* Some systems do not have this flag; it is superfluous. */
|
|
# define MAP_FILE 0
|
|
# endif
|
|
# ifndef MAP_INHERIT
|
|
/* Some systems might lack this; they lose. */
|
|
# define MAP_INHERIT 0
|
|
# endif
|
|
filedata = (void *) __mmap ((caddr_t) 0, st.st_size, PROT_READ,
|
|
MAP_FILE|MAP_COPY|MAP_INHERIT, fd, 0);
|
|
if ((void *) filedata != MAP_FAILED)
|
|
{
|
|
if (st.st_size < sizeof (*filedata))
|
|
/* This cannot be a locale data file since it's too small. */
|
|
goto puntfd;
|
|
}
|
|
else
|
|
{
|
|
if (errno == ENOSYS)
|
|
{
|
|
#endif /* _POSIX_MAPPED_FILES */
|
|
/* No mmap; allocate a buffer and read from the file. */
|
|
mmaped = 0;
|
|
filedata = malloc (st.st_size);
|
|
if (filedata != NULL)
|
|
{
|
|
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)
|
|
__set_errno (EINVAL); /* Bizarreness going on. */
|
|
goto puntfd;
|
|
}
|
|
p += nread;
|
|
to_read -= nread;
|
|
}
|
|
}
|
|
else
|
|
goto puntfd;
|
|
__set_errno (save_err);
|
|
#ifdef _POSIX_MAPPED_FILES
|
|
}
|
|
else
|
|
goto puntfd;
|
|
}
|
|
#endif /* _POSIX_MAPPED_FILES */
|
|
|
|
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:
|
|
#ifdef _POSIX_MAPPED_FILES
|
|
if (mmaped)
|
|
__munmap ((caddr_t) filedata, st.st_size);
|
|
else
|
|
#endif /* _POSIX_MAPPED_FILES */
|
|
free (filedata);
|
|
puntfd:
|
|
__close (fd);
|
|
return;
|
|
}
|
|
}
|
|
|
|
#define W(word) SWAP (&(word))
|
|
|
|
if (W (filedata->nstrings) < _nl_category_num_items[category] ||
|
|
(sizeof *filedata + W (filedata->nstrings) * sizeof (unsigned int)
|
|
>= (size_t) st.st_size))
|
|
{
|
|
/* Insufficient data. */
|
|
__set_errno (EINVAL);
|
|
goto puntmap;
|
|
}
|
|
|
|
newdata = malloc (sizeof *newdata +
|
|
(_nl_category_num_items[category]
|
|
* sizeof (union locale_data_value)));
|
|
if (! newdata)
|
|
goto puntmap;
|
|
|
|
newdata->name = NULL; /* This will be filled if necessary in findlocale.c. */
|
|
newdata->filedata = (void *) filedata;
|
|
newdata->filesize = st.st_size;
|
|
newdata->mmaped = mmaped;
|
|
newdata->usage_count = 0;
|
|
newdata->nstrings = _nl_category_num_items[category];
|
|
for (cnt = 0; cnt < newdata->nstrings; ++cnt)
|
|
{
|
|
off_t idx = W (filedata->strindex[cnt]);
|
|
if (idx >= newdata->filesize)
|
|
{
|
|
free (newdata);
|
|
__set_errno (EINVAL);
|
|
goto puntmap;
|
|
}
|
|
if (_nl_value_types[category][cnt] == word)
|
|
newdata->values[cnt].word = W (*((u_int32_t *) (newdata->filedata
|
|
+ idx)));
|
|
else
|
|
newdata->values[cnt].string = newdata->filedata + idx;
|
|
}
|
|
|
|
__close (fd);
|
|
file->data = newdata;
|
|
}
|
|
|
|
void
|
|
_nl_unload_locale (struct locale_data *locale)
|
|
{
|
|
if (locale->name != NULL)
|
|
free ((void *) locale->name);
|
|
|
|
#ifdef _POSIX_MAPPED_FILES
|
|
if (locale->mmaped)
|
|
__munmap ((caddr_t) locale->filedata, locale->filesize);
|
|
else
|
|
#endif
|
|
free ((void *) locale->filedata);
|
|
|
|
free (locale);
|
|
}
|