+1998-04-29 Ulrich Drepper <drepper@cygnus.com>
+
+ * intl/localealias.c (read_alias_file): Use unsigned char for
+ local variables. Remove unused variable tp.
+ * intl/l10nflist.c (_nl_normalize_codeset): Use unsigned char *
+ for type of codeset. For loosing Solaris systems.
+ * intl/loadinfo.h: Adapt prototype of _nl_normalize_codeset.
+ * intl/bindtextdom.c (BINDTEXTDOMAIN): Don't define local variable
+ len if not needed.
+ Patches by Jim Meyering.
+
+1998-04-28 Ulrich Drepper <drepper@cygnus.com>
+
+ * loadmsgcat.c (_nl_load_domain): Don't assign the element use_mmap if
+ mmap is not supported.
+
+ * hash-string.h: Don't include <values.h>.
+
+1998-04-27 Ulrich Drepper <drepper@cygnus.com>
+
+ * textdomain.c: Use strdup is available.
+
+ * localealias.c: Define HAVE_MEMPCPY so that we can use this
+ function. Define and use semapahores to protect modfication of
+ global objects when compiling for glibc. Add code to allow
+ freeing alias table.
+
+ * l10nflist.c: Don't assume stpcpy not being a macro.
+
+ * gettextP.h: Define internal_function macri if not already done.
+ Use glibc byte-swap macros instead of defining SWAP when compiled
+ for glibc.
+ (struct loaded_domain): Add elements to allow unloading.
+
+ * Makefile.in (distclean): Don't remove libintl.h here.
+
+ * bindtextdomain.c: Carry over changes from glibc. Use strdup if
+ available.
+
+ * dcgettext.c: Don't assume stpcpy not being a macro. Mark internal
+ functions. Add memory freeing code for glibc.
+
+ * dgettext.c: Update copyright.
+
+ * explodename.c: Include stdlib.h and string.h only if they exist.
+ Use strings.h eventually.
+
+ * finddomain.c: Mark internal functions. Use strdup if available.
+ Add memory freeing code for glibc.
+
+1997-10-10 20:00 Ulrich Drepper <drepper@cygnus.com>
+
+ * libgettext.h: Fix dummy textdomain and bindtextdomain macros.
+ They should return reasonable values.
+ Reported by Tom Tromey <tromey@cygnus.com>.
+
+1997-09-16 03:33 Ulrich Drepper <drepper@cygnus.com>
+
+ * libgettext.h: Define PARAMS also to `args' if __cplusplus is defined.
+ * intlh.inst.in: Likewise.
+ Reported by Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>.
+
+ * libintl.glibc: Update from current glibc version.
+
1997-09-06 02:10 Ulrich Drepper <drepper@cygnus.com>
* intlh.inst.in: Reformat copyright.
/* Implementation of the bindtextdomain(3) function
- Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
prefix. So we have to make a difference here. */
#ifdef _LIBC
# define BINDTEXTDOMAIN __bindtextdomain
-# define strdup(str) __strdup (str)
+# ifndef strdup
+# define strdup(str) __strdup (str)
+# endif
#else
# define BINDTEXTDOMAIN bindtextdomain__
#endif
else
{
/* We have to create a new binding. */
+#if !defined _LIBC && !defined HAVE_STRDUP
size_t len;
+#endif
struct binding *new_binding =
(struct binding *) malloc (sizeof (*new_binding));
-/* Implementation of the dcgettext(3) function
- Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+/* Implementation of the dcgettext(3) function.
+ Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
because some ANSI C functions will require linking with this object
file and the name space must not be polluted. */
# define getcwd __getcwd
-# define stpcpy __stpcpy
+# ifndef stpcpy
+# define stpcpy __stpcpy
+# endif
#else
# if !defined HAVE_GETCWD
char *getwd ();
/* Prototypes for local functions. */
static char *find_msg PARAMS ((struct loaded_l10nfile *domain_file,
- const char *msgid));
-static const char *category_to_name PARAMS ((int category));
+ const char *msgid)) internal_function;
+static const char *category_to_name PARAMS ((int category)) internal_function;
static const char *guess_category_value PARAMS ((int category,
- const char *categoryname));
+ const char *categoryname))
+ internal_function;
/* For those loosing systems which don't have `alloca' we have to add
static char *
+internal_function
find_msg (domain_file, msgid)
struct loaded_l10nfile *domain_file;
const char *msgid;
/* Return string representation of locale CATEGORY. */
static const char *
+internal_function
category_to_name (category)
int category;
{
/* Guess value of current locale from value of the environment variables. */
static const char *
+internal_function
guess_category_value (category, categoryname)
int category;
const char *categoryname;
return dest - 1;
}
#endif
+
+
+#ifdef _LIBC
+/* If we want to free all resources we have to do some work at
+ program's end. */
+static void __attribute__ ((unused))
+free_mem (void)
+{
+ struct binding *runp;
+
+ for (runp = _nl_domain_bindings; runp != NULL; runp = runp->next)
+ {
+ free (runp->domainname);
+ if (runp->dirname != _nl_default_dirname)
+ /* Yes, this is a pointer comparison. */
+ free (runp->dirname);
+ }
+
+ if (_nl_current_default_domain != _nl_default_default_domain)
+ /* Yes, again a pointer comparison. */
+ free ((char *) _nl_current_default_domain);
+}
+
+text_set_element (__libc_subfreeres, free_mem);
+#endif
-/* dgettext.c -- implementation of the dgettext(3) function
- Copyright (C) 1995 Software Foundation, Inc.
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-This program 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 General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+/* Implementation of the dgettext(3) function
+ Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#ifdef HAVE_CONFIG_H
# include <config.h>
-/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
This program is free software; you can redistribute it and/or modify
# include <config.h>
#endif
-#include <stdlib.h>
-#include <string.h>
+#if defined STDC_HEADERS || defined _LIBC
+# include <stdlib.h>
+#endif
+
+#if defined HAVE_STRING_H || defined _LIBC
+# include <string.h>
+#else
+# include <strings.h>
+#endif
#include <sys/types.h>
#include "loadinfo.h"
/* Handle list of needed message catalogs
- Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
This program is free software; you can redistribute it and/or modify
the DOMAINNAME and CATEGORY parameters with respect to the currently
established bindings. */
struct loaded_l10nfile *
+internal_function
_nl_find_domain (dirname, locale, domainname)
const char *dirname;
char *locale;
language[_territory][+audience][+special][,[sponsor][_revision]]
- Beside the first all of them are allowed to be missing. If the
- full specified locale is not found, the less specific one are
- looked for. The various part will be stripped of according to
+ Beside the first part all of them are allowed to be missing. If
+ the full specified locale is not found, the less specific one are
+ looked for. The various parts will be stripped off according to
the following order:
(1) revision
(2) sponsor
alias_value = _nl_expand_alias (locale);
if (alias_value != NULL)
{
+#if defined _LIBC || defined HAVE_STRDUP
+ locale = strdup (alias_value);
+ if (locale == NULL)
+ return NULL;
+#else
size_t len = strlen (alias_value) + 1;
locale = (char *) malloc (len);
if (locale == NULL)
return NULL;
memcpy (locale, alias_value, len);
+#endif
}
/* Now we determine the single parts of the locale name. First
return retval;
}
+
+
+#ifdef _LIBC
+static void __attribute__ ((unused))
+free_mem (void)
+{
+ struct loaded_l10nfile *runp = _nl_loaded_domains;
+
+ while (runp != NULL)
+ {
+ struct loaded_l10nfile *here = runp;
+ if (runp->data != NULL)
+ _nl_unload_domain ((struct loaded_domain *) runp->data);
+ runp = runp->next;
+ free (here);
+ }
+}
+
+text_set_element (__libc_subfreeres, free_mem);
+#endif
-/* Implementation of gettext(3) function
+/* Implementation of gettext(3) function.
Copyright (C) 1995, 1997 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
-/* Internal header for GNU gettext internationalization functions
+/* Internal header for GNU gettext internationalization functions.
Copyright (C) 1995, 1997 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
/* Header describing internals of gettext library
- Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
+ Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
# endif
#endif
+#ifndef internal_function
+# define internal_function
+#endif
+
#ifndef W
# define W(flag, data) ((flag) ? SWAP (data) : (data))
#endif
+#ifdef _LIBC
+# include <byteswap.h>
+# define SWAP(i) bswap_32 (i)
+#else
static nls_uint32 SWAP PARAMS ((nls_uint32 i));
static inline nls_uint32
{
return (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24);
}
+#endif
struct loaded_domain
{
const char *data;
+ int use_mmap;
+ size_t mmap_size;
int must_swap;
nls_uint32 nstrings;
struct string_desc *orig_tab;
struct loaded_l10nfile *_nl_find_domain PARAMS ((const char *__dirname,
char *__locale,
- const char *__domainname));
-void _nl_load_domain PARAMS ((struct loaded_l10nfile *__domain));
+ const char *__domainname))
+ internal_function;
+void _nl_load_domain PARAMS ((struct loaded_l10nfile *__domain))
+ internal_function;
+void _nl_unload_domain PARAMS ((struct loaded_domain *__domain))
+ internal_function;
/* @@ begin of epilog @@ */
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#ifdef HAVE_VALUES_H
-# include <values.h>
-#endif
-
/* @@ end of prolog @@ */
#ifndef PARAMS
#define __USE_GNU_GETTEXT 1
#ifndef PARAMS
-# if __STDC__
+# if __STDC__ || defined __cplusplus
# define PARAMS(args) args
# else
# define PARAMS(args) ()
/* Handle list of needed message catalogs
Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
- Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
/* Rename the non ANSI C functions. This is required by the standard
because some ANSI C functions will require linking with this object
file and the name space must not be polluted. */
-# define stpcpy(dest, src) __stpcpy(dest, src)
+# ifndef stpcpy
+# define stpcpy(dest, src) __stpcpy(dest, src)
+# endif
#else
# ifndef HAVE_STPCPY
static char *stpcpy PARAMS ((char *dest, const char *src));
names. */
const char *
_nl_normalize_codeset (codeset, name_len)
- const char *codeset;
+ const unsigned char *codeset;
size_t name_len;
{
int len = 0;
/* Message catalogs for internationalization.
- Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
include protection above. But the systems header might perhaps also
define _LIBINTL_H and therefore we have to protect the definition here. */
-#if !defined (_LIBINTL_H) || !defined (_LIBGETTEXT_H)
-#if !defined (_LIBINTL_H)
+#if !defined _LIBINTL_H || !defined _LIBGETTEXT_H
+#ifndef _LIBINTL_H
# define _LIBINTL_H 1
#endif
#define _LIBGETTEXT_H 1
/* @@ end of prolog @@ */
#ifndef PARAMS
-# if __STDC__
+# if __STDC__ || defined __cplusplus
# define PARAMS(args) args
# else
# define PARAMS(args) ()
# define gettext(Msgid) (Msgid)
# define dgettext(Domainname, Msgid) (Msgid)
# define dcgettext(Domainname, Msgid, Category) (Msgid)
-# define textdomain(Domainname) while (0) /* nothing */
-# define bindtextdomain(Domainname, Dirname) while (0) /* nothing */
+# define textdomain(Domainname) ((char *) Domainname)
+# define bindtextdomain(Domainname, Dirname) ((char *) Dirname)
#endif
-/* libgettext.h -- Message catalogs for internationalization.
-Copyright (C) 1995 Free Software Foundation, Inc.
-This file is part of the GNU C Library.
-Contributed by Ulrich Drepper.
-This file is derived from the file libgettext.h in the GNU gettext package.
-
-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. */
+/* Message catalogs for internationalization.
+ Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
+ This file is derived from the file libgettext.h in the GNU gettext package.
+
+ This file is part of the GNU C Library. Its master source is NOT part of
+ the C library, however.
+
+ 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. */
#ifndef _LIBINTL_H
#define _LIBINTL_H 1
-#include <features.h>
-
-#include <locale.h>
-#define __need_NULL
-#include <stddef.h>
+#include <features.h>
/* We define an additional symbol to signal that we use the GNU
implementation of gettext. */
/* Optimized version of the function above. */
-#if defined __OPTIMIZED
-/* These must be a macro. Inlined functions are useless because the
+#if defined __OPTIMIZE__
+
+/* We need NULL for `gettext'. */
+# define __need_NULL
+# include <stddef.h>
+
+/* We need LC_MESSAGES for `dgettext'. */
+# include <locale.h>
+
+/* These must be macros. Inlined functions are useless because the
`__builtin_constant_p' predicate in dcgettext would always return
false. */
dcgettext (domainname, msgid, LC_MESSAGES)
# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+/* Variable defined in loadmsgcat.c which gets incremented every time a
+ new catalog is loaded. */
+extern int _nl_msg_cat_cntr;
+
# define dcgettext(domainname, msgid, category) \
(__extension__ \
({ \
- char *result; \
+ char *__result; \
if (__builtin_constant_p (msgid)) \
{ \
- extern int _nl_msg_cat_cntr; \
static char *__translation__; \
static int __catalog_counter__; \
if (! __translation__ || __catalog_counter__ != _nl_msg_cat_cntr) \
__dcgettext ((domainname), (msgid), (category)); \
__catalog_counter__ = _nl_msg_cat_cntr; \
} \
- result = __translation__; \
+ __result = __translation__; \
} \
else \
- result = __dcgettext ((domainname), (msgid), (category)); \
- result; \
+ __result = __dcgettext ((domainname), (msgid), (category)); \
+ __result; \
}))
# endif
#endif /* Optimizing. */
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
#ifndef PARAMS
# if __STDC__
# define PARAMS(args) args
};
-extern const char *_nl_normalize_codeset PARAMS ((const char *codeset,
+extern const char *_nl_normalize_codeset PARAMS ((const unsigned char *codeset,
size_t name_len));
extern struct loaded_l10nfile *
-/* Load needed message catalogs
- Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+/* Load needed message catalogs.
+ Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
/* Rename the non ISO C functions. This is required by the standard
because some ISO C functions will require linking with this object
file and the name space must not be polluted. */
-# define fstat __fstat
# define open __open
# define close __close
# define read __read
/* Load the message catalogs specified by FILENAME. If it is no valid
message catalog do nothing. */
void
+internal_function
_nl_load_domain (domain_file)
struct loaded_l10nfile *domain_file;
{
int fd;
+ size_t size;
struct stat st;
struct mo_file_header *data = (struct mo_file_header *) -1;
#if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
/* We must know about the size of the file. */
if (fstat (fd, &st) != 0
- && st.st_size < (off_t) sizeof (struct mo_file_header))
+ || (size = (size_t) st.st_size) != st.st_size
+ || size < sizeof (struct mo_file_header))
{
/* Something went wrong. */
close (fd);
|| defined _LIBC
/* Now we are ready to load the file. If mmap() is available we try
this first. If not available or it failed we try to load it. */
- data = (struct mo_file_header *) mmap (NULL, st.st_size, PROT_READ,
+ data = (struct mo_file_header *) mmap (NULL, size, PROT_READ,
MAP_PRIVATE, fd, 0);
if (data != (struct mo_file_header *) -1)
it manually. */
if (data == (struct mo_file_header *) -1)
{
- off_t to_read;
+ size_t to_read;
char *read_ptr;
- data = (struct mo_file_header *) malloc (st.st_size);
+ data = (struct mo_file_header *) malloc (size);
if (data == NULL)
return;
- to_read = st.st_size;
+ to_read = size;
read_ptr = (char *) data;
do
{
#if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
|| defined _LIBC
if (use_mmap)
- munmap ((caddr_t) data, st.st_size);
+ munmap ((caddr_t) data, size);
else
#endif
free (data);
domain = (struct loaded_domain *) domain_file->data;
domain->data = (char *) data;
+#if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
+ || defined _LIBC
+ domain->use_mmap = use_mmap;
+#endif
+ domain->mmap_size = size;
domain->must_swap = data->magic != _MAGIC;
/* Fill in the information about the available tables. */
#if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
|| defined _LIBC
if (use_mmap)
- munmap ((caddr_t) data, st.st_size);
+ munmap ((caddr_t) data, size);
else
#endif
free (data);
translations invalid. */
++_nl_msg_cat_cntr;
}
+
+
+#ifdef _LIBC
+void
+internal_function
+_nl_unload_domain (domain)
+ struct loaded_domain *domain;
+{
+ if (domain->use_mmap)
+ munmap ((caddr_t) domain->data, domain->mmap_size);
+ else
+ free ((void *) domain->data);
+
+ free (domain);
+}
+#endif
-/* Handle aliases for locale names
- Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+/* Handle aliases for locale names.
+ Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
This program is free software; you can redistribute it and/or modify
because some ANSI C functions will require linking with this object
file and the name space must not be polluted. */
# define strcasecmp __strcasecmp
+
+# define mempcpy __mempcpy
+# define HAVE_MEMPCPY 1
+
+/* We need locking here since we can be called from different places. */
+# include <bits/libc-lock.h>
+
+__libc_lock_define_initialized (static, lock);
#endif
};
+static char *string_space = NULL;
+static size_t string_space_act = 0;
+static size_t string_space_max = 0;
static struct alias_map *map;
static size_t nmap = 0;
static size_t maxmap = 0;
/* Prototypes for local functions. */
-static size_t read_alias_file PARAMS ((const char *fname, int fname_len));
+static size_t read_alias_file PARAMS ((const char *fname, int fname_len))
+ internal_function;
static void extend_alias_table PARAMS ((void));
static int alias_compare PARAMS ((const struct alias_map *map1,
const struct alias_map *map2));
{
static const char *locale_alias_path = LOCALE_ALIAS_PATH;
struct alias_map *retval;
+ const char *result = NULL;
size_t added;
+#ifdef _LIBC
+ __libc_lock_lock (lock);
+#endif
+
do
{
struct alias_map item;
/* We really found an alias. Return the value. */
if (retval != NULL)
- return retval->value;
+ {
+ result = retval->value;
+ break;
+ }
/* Perhaps we can find another alias file. */
added = 0;
}
while (added != 0);
- return NULL;
+#ifdef _LIBC
+ __libc_lock_unlock (lock);
+#endif
+
+ return result;
}
static size_t
+internal_function
read_alias_file (fname, fname_len)
const char *fname;
int fname_len;
full_fname = (char *) alloca (fname_len + sizeof aliasfile);
ADD_BLOCK (block_list, full_fname);
+#ifdef HAVE_MEMPCPY
+ mempcpy (mempcpy (full_fname, fname, fname_len),
+ aliasfile, sizeof aliasfile);
+#else
memcpy (full_fname, fname, fname_len);
memcpy (&full_fname[fname_len], aliasfile, sizeof aliasfile);
+#endif
fp = fopen (full_fname, "r");
if (fp == NULL)
b) these fields must be usable as file names and so must not
be that long
*/
- char buf[BUFSIZ];
- char *alias;
- char *value;
- char *cp;
+ unsigned char buf[BUFSIZ];
+ unsigned char *alias;
+ unsigned char *value;
+ unsigned char *cp;
- if (fgets (buf, BUFSIZ, fp) == NULL)
+ if (fgets (buf, sizeof buf, fp) == NULL)
/* EOF reached. */
break;
+ /* Possibly not the whole line fits into the buffer. Ignore
+ the rest of the line. */
+ if (strchr (buf, '\n') == NULL)
+ {
+ char altbuf[BUFSIZ];
+ do
+ if (fgets (altbuf, sizeof altbuf, fp) == NULL)
+ /* Make sure the inner loop will be left. The outer loop
+ will exit at the `feof' test. */
+ break;
+ while (strchr (altbuf, '\n') == NULL);
+ }
+
cp = buf;
/* Ignore leading white space. */
while (isspace (cp[0]))
if (cp[0] != '\0')
{
- char *tp;
- size_t len;
+ size_t alias_len;
+ size_t value_len;
value = cp++;
while (cp[0] != '\0' && !isspace (cp[0]))
if (nmap >= maxmap)
extend_alias_table ();
- /* We cannot depend on strdup available in the libc. Sigh! */
- len = strlen (alias) + 1;
- tp = (char *) malloc (len);
- if (tp == NULL)
- {
- FREE_BLOCKS (block_list);
- return added;
- }
- memcpy (tp, alias, len);
- map[nmap].alias = tp;
+ alias_len = strlen (alias) + 1;
+ value_len = strlen (value) + 1;
- len = strlen (value) + 1;
- tp = (char *) malloc (len);
- if (tp == NULL)
+ if (string_space_act + alias_len + value_len > string_space_max)
{
- FREE_BLOCKS (block_list);
- return added;
+ /* Increase size of memory pool. */
+ size_t new_size = (string_space_max
+ + (alias_len + value_len > 1024
+ ? alias_len + value_len : 1024));
+ char *new_pool = (char *) realloc (string_space, new_size);
+ if (new_pool == NULL)
+ {
+ FREE_BLOCKS (block_list);
+ return added;
+ }
+ string_space = new_pool;
+ string_space_max = new_size;
}
- memcpy (tp, value, len);
- map[nmap].value = tp;
+
+ map[nmap].alias = memcpy (&string_space[string_space_act],
+ alias, alias_len);
+ string_space_act += alias_len;
+
+ map[nmap].value = memcpy (&string_space[string_space_act],
+ value, value_len);
+ string_space_act += value_len;
++nmap;
++added;
}
}
-
- /* Possibly not the whole line fits into the buffer. Ignore
- the rest of the line. */
- while (strchr (cp, '\n') == NULL)
- {
- cp = buf;
- if (fgets (buf, BUFSIZ, fp) == NULL)
- /* Make sure the inner loop will be left. The outer loop
- will exit at the `feof' test. */
- *cp = '\n';
- }
}
/* Should we test for ferror()? I think we have to silently ignore
struct alias_map *new_map;
new_size = maxmap == 0 ? 100 : 2 * maxmap;
- new_map = (struct alias_map *) malloc (new_size
- * sizeof (struct alias_map));
+ new_map = (struct alias_map *) realloc (map, (new_size
+ * sizeof (struct alias_map)));
if (new_map == NULL)
/* Simply don't extend: we don't have any more core. */
return;
- memcpy (new_map, map, nmap * sizeof (struct alias_map));
-
- if (maxmap != 0)
- free (map);
-
map = new_map;
maxmap = new_size;
}
+#ifdef _LIBC
+static void __attribute__ ((unused))
+free_mem (void)
+{
+ if (string_space != NULL)
+ free (string_space);
+ if (map != NULL)
+ free (map);
+}
+text_set_element (__libc_subfreeres, free_mem);
+#endif
+
+
static int
alias_compare (map1, map2)
const struct alias_map *map1;
-/* Implementation of the textdomain(3) function
- Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+/* Implementation of the textdomain(3) function.
+ Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
This program is free software; you can redistribute it and/or modify
prefix. So we have to make a difference here. */
#ifdef _LIBC
# define TEXTDOMAIN __textdomain
-# define strdup(str) __strdup (str)
+# ifndef strdup
+# define strdup(str) __strdup (str)
+# endif
#else
# define TEXTDOMAIN textdomain__
#endif