summaryrefslogtreecommitdiff
path: root/iconv/gconv_conf.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2000-06-19 21:12:06 +0000
committerUlrich Drepper <drepper@redhat.com>2000-06-19 21:12:06 +0000
commitd620426811688301eb1cbe6e63773d6430b2706e (patch)
tree555eb9182298ec1e56db8a5de4f62daa2e654321 /iconv/gconv_conf.c
parent01da56ba764e6abc52bfe9a1feeb79d3d67346d1 (diff)
Update.
2000-06-19 Ulrich Drepper <drepper@redhat.com> * iconv/gconv.h (__gconv_trans_fct): Add new parameter. General namespace cleanup. (struct __gconv_trans_data): Add next field. (struct __gconv_step_data): Make __trans a pointer. * iconv/gconv_conf.c: Split out code to find gconv directories from __gconv_read_conf in new functions. * iconv/gconv_int.h: Define new data structure and declare new functions for handling of gconv directory list. * iconv/gconv_open.c: Allow more than one error handling step being used. Call function to load error handling module if it is none of the builtin transformations. * iconv/gconv_close.c: Add code to free transliteration data. * iconv/gconv_trans.c: Add functions to load and unload modules implementing transliteration etc. * iconv/skeleton.c: Call all context functions now that more than one module is allowed. * iconv/loop.c (STANDARD_ERR_HANDLING): New macro. * iconv/gconv_simple.c: Use STANDARD_ERR_HANDLING macro for places where the full error handling using transliteration is needed. * iconvdata/8bit-gap.c: Likewise. * iconvdata/8bit-generic.c: Likewise. * iconvdata/ansi_x3.110.c: Likewise. * iconvdata/big5.c: Likewise. * iconvdata/big5hkscs.c: Likewise. * iconvdata/euc-cn.c: Likewise. * iconvdata/euc-jp.c: Likewise. * iconvdata/euc-kr.c: Likewise. * iconvdata/euc-tw.c: Likewise. * iconvdata/gbgbk.c: Likewise. * iconvdata/gbk.c: Likewise. * iconvdata/iso-2022-cn.c: Likewise. * iconvdata/iso-2022-jp.c: Likewise. * iconvdata/iso-2022-kr.c: Likewise. * iconvdata/iso646.c: Likewise. * iconvdata/iso8859-1.c: Likewise. * iconvdata/iso_6937-2.c: Likewise. * iconvdata/iso_6937.c: Likewise. * iconvdata/johab.c: Likewise. * iconvdata/sjis.c: Likewise. * iconvdata/t.61.c: Likewise. * iconvdata/uhc.c: Likewise. * iconvdata/unicode.c: Likewise. * iconvdata/utf-16.c: Likewise. * libio/iofwide.c: Reset __trans member of __gconv_trans_data structure correctly after last change. * wcsmbs/btowc.c: Likewise. * wcsmbs/mbrtowc.c: Likewise. * wcsmbs/mbsnrtowcs.c: Likewise. * wcsmbs/mbsrtowcs.c: Likewise. * wcsmbs/wcrtomb.c: Likewise. * wcsmbs/wcsnrtombs.c: Likewise. * wcsmbs/wcsrtombs.c: Likewise. * wcsmbs/wctob.c: Likewise. * localedata/Makefile: Set -Wno-format for some files since gcc does not know all the format specifiers. 2000-06-18 Ulrich Drepper <drepper@redhat.com> * locale/loadlocale.c (_nl_unload_locale): Remove a bit of unneeded code. * locale/lc-time.c (_nl_init_era_entries): Likewise.
Diffstat (limited to 'iconv/gconv_conf.c')
-rw-r--r--iconv/gconv_conf.c153
1 files changed, 124 insertions, 29 deletions
diff --git a/iconv/gconv_conf.c b/iconv/gconv_conf.c
index 0d25c22416..480b459134 100644
--- a/iconv/gconv_conf.c
+++ b/iconv/gconv_conf.c
@@ -1,5 +1,5 @@
/* Handle configuration data.
- Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
+ Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
@@ -18,6 +18,7 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
+#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
@@ -34,6 +35,14 @@
/* This is the default path where we look for module lists. */
static const char default_gconv_path[] = GCONV_PATH;
+/* The path element in use. */
+const struct path_elem *__gconv_path_elem;
+/* Maximum length of a single path element. */
+size_t __gconv_max_path_elem_len;
+
+/* We use the following struct if we couldn't allocate memory. */
+static const struct path_elem empty_path_elem;
+
/* Name of the file containing the module information in the directories
along the path. */
static const char gconv_conf_filename[] = "gconv-modules";
@@ -497,48 +506,125 @@ read_conf_file (const char *filename, const char *directory, size_t dir_len,
/* Otherwise ignore the line. */
}
- if (line != NULL)
- free (line);
+ free (line);
+
fclose (fp);
}
+/* Determine the directories we are looking for data in. */
+void
+__gconv_get_path (void)
+{
+ struct path_elem *result;
+ __libc_lock_define_initialized (static, lock);
+
+ __libc_lock_lock (lock);
+
+ /* Make sure there wasn't a second thread doing it already. */
+ result = (struct path_elem *) __gconv_path_elem;
+ if (result == NULL)
+ {
+ /* Determine the complete path first. */
+ const char *user_path;
+ char *gconv_path;
+ size_t gconv_path_len;
+ char *elem;
+ char *oldp;
+ char *cp;
+ int nelems;
+
+ user_path = __secure_getenv ("GCONV_PATH");
+ if (user_path == NULL)
+ {
+ /* No user-defined path. Make a modifiable copy of the
+ default path. */
+ gconv_path = strdupa (default_gconv_path);
+ gconv_path_len = sizeof (default_gconv_path);
+ }
+ else
+ {
+ /* Append the default path to the user-defined path. */
+ size_t user_len = strlen (user_path);
+
+ gconv_path_len = user_len + 1 + sizeof (default_gconv_path);
+ gconv_path = alloca (gconv_path_len);
+ __mempcpy (__mempcpy (__mempcpy (gconv_path, user_path, user_len),
+ ":", 1),
+ default_gconv_path, sizeof (default_gconv_path));
+ }
+
+ /* In a first pass we calculate the number of elements. */
+ oldp = NULL;
+ cp = strchr (gconv_path, ':');
+ nelems = 1;
+ while (cp != NULL)
+ {
+ if (cp != oldp + 1)
+ ++nelems;
+ oldp = cp;
+ cp = strchr (cp + 1, ':');
+ }
+
+ /* Allocate the memory for the result. */
+ result = (struct path_elem *) malloc ((nelems + 1)
+ * sizeof (struct path_elem)
+ + gconv_path_len + nelems);
+ if (result != NULL)
+ {
+ char *strspace = (char *) &result[nelems + 1];
+ int n = 0;
+
+ /* Separate the individual parts. */
+ __gconv_max_path_elem_len = 0;
+ elem = __strtok_r (gconv_path, ":", &gconv_path);
+ assert (elem != NULL);
+ do
+ {
+ result[n].name = strspace;
+ strspace = __stpcpy (strspace, elem);
+ if (strspace[-1] != '/')
+ *strspace++ = '/';
+
+ result[n].len = strspace - result[n].name;
+ if (result[n].len > __gconv_max_path_elem_len)
+ __gconv_max_path_elem_len = result[n].len;
+
+ *strspace++ = '\0';
+ ++n;
+ }
+ while ((elem = __strtok_r (NULL, ":", &gconv_path)) != NULL);
+
+ result[n].name = NULL;
+ result[n].len = 0;
+ }
+
+ __gconv_path_elem = result ?: &empty_path_elem;
+ }
+
+ __libc_lock_unlock (lock);
+}
+
+
/* Read all configuration files found in the user-specified and the default
path. */
void
__gconv_read_conf (void)
{
- const char *user_path = __secure_getenv ("GCONV_PATH");
- char *gconv_path, *elem;
void *modules = NULL;
size_t nmodules = 0;
int save_errno = errno;
size_t cnt;
- if (user_path == NULL)
- /* No user-defined path. Make a modifiable copy of the default path. */
- gconv_path = strdupa (default_gconv_path);
- else
- {
- /* Append the default path to the user-defined path. */
- size_t user_len = strlen (user_path);
-
- gconv_path = alloca (user_len + 1 + sizeof (default_gconv_path));
- __mempcpy (__mempcpy (__mempcpy (gconv_path, user_path, user_len),
- ":", 1),
- default_gconv_path, sizeof (default_gconv_path));
- }
+ /* Find out where we have to look. */
+ if (__gconv_path_elem == NULL)
+ __gconv_get_path ();
- elem = __strtok_r (gconv_path, ":", &gconv_path);
- while (elem != NULL)
+ for (cnt = 0; __gconv_path_elem[cnt].name != NULL; ++cnt)
{
-#ifndef MAXPATHLEN
- /* We define a reasonable limit. */
-# define MAXPATHLEN 4096
-#endif
- char real_elem[MAXPATHLEN];
+ char real_elem[__gconv_max_path_elem_len + sizeof (gconv_conf_filename)];
- if (__realpath (elem, real_elem) != NULL)
+ if (__realpath (__gconv_path_elem[cnt].name, real_elem) != NULL)
{
size_t elem_len = strlen (real_elem);
char *filename;
@@ -551,9 +637,6 @@ __gconv_read_conf (void)
/* Read the next configuration file. */
read_conf_file (filename, real_elem, elem_len, &modules, &nmodules);
}
-
- /* Get next element in the path. */
- elem = __strtok_r (NULL, ":", &gconv_path);
}
/* Add the internal modules. */
@@ -586,3 +669,15 @@ __gconv_read_conf (void)
/* Restore the error number. */
__set_errno (save_errno);
}
+
+
+
+/* Free all resources if necessary. */
+static void __attribute__ ((unused))
+free_mem (void)
+{
+ if (__gconv_path_elem != NULL && __gconv_path_elem != &empty_path_elem)
+ free ((void *) __gconv_path_elem);
+}
+
+text_set_element (__libc_subfreeres, free_mem);