about summary refs log tree commit diff
path: root/iconv
diff options
context:
space:
mode:
Diffstat (limited to 'iconv')
-rw-r--r--iconv/Versions4
-rw-r--r--iconv/gconv_cache.c57
-rw-r--r--iconv/gconv_db.c16
-rw-r--r--iconv/gconv_int.h13
-rw-r--r--iconv/iconv_prog.c23
5 files changed, 72 insertions, 41 deletions
diff --git a/iconv/Versions b/iconv/Versions
index 0661c8ce4c..7f09ed49c4 100644
--- a/iconv/Versions
+++ b/iconv/Versions
@@ -4,7 +4,7 @@ libc {
     iconv_open; iconv; iconv_close;
   }
   GLIBC_PRIVATE {
-    # variables shared with iconv program
-    __gconv_alias_db; __gconv_modules_db; __gconv_cache;
+    # functions shared with iconv program
+    __gconv_get_alias_db; __gconv_get_modules_db; __gconv_get_cache;
   }
 }
diff --git a/iconv/gconv_cache.c b/iconv/gconv_cache.c
index a2beee06fa..56d8c37519 100644
--- a/iconv/gconv_cache.c
+++ b/iconv/gconv_cache.c
@@ -1,5 +1,5 @@
 /* Cache handling for iconv modules.
-   Copyright (C) 2001 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 2001.
 
@@ -31,11 +31,18 @@
 
 #include "../intl/hash-string.h"
 
-void *__gconv_cache;
+static void *gconv_cache;
 static size_t cache_size;
 static int cache_malloced;
 
 
+void *
+__gconv_get_cache (void)
+{
+  return gconv_cache;
+}
+
+
 int
 internal_function
 __gconv_load_cache (void)
@@ -70,25 +77,25 @@ __gconv_load_cache (void)
   /* Make the file content available.  */
   cache_size = st.st_size;
 #ifdef _POSIX_MAPPED_FILES
-  __gconv_cache = __mmap (NULL, cache_size, PROT_READ, MAP_SHARED, fd, 0);
-  if (__builtin_expect (__gconv_cache == MAP_FAILED, 0))
+  gconv_cache = __mmap (NULL, cache_size, PROT_READ, MAP_SHARED, fd, 0);
+  if (__builtin_expect (gconv_cache == MAP_FAILED, 0))
 #endif
     {
       size_t already_read;
 
-      __gconv_cache = malloc (cache_size);
-      if (__gconv_cache == NULL)
+      gconv_cache = malloc (cache_size);
+      if (gconv_cache == NULL)
 	goto close_and_exit;
 
       already_read = 0;
       do
 	{
-	  ssize_t n = __read (fd, (char *) __gconv_cache + already_read,
+	  ssize_t n = __read (fd, (char *) gconv_cache + already_read,
 			      cache_size - already_read);
 	  if (__builtin_expect (n, 0) == -1)
 	    {
-	      free (__gconv_cache);
-	      __gconv_cache = NULL;
+	      free (gconv_cache);
+	      gconv_cache = NULL;
 	      goto close_and_exit;
 	    }
 
@@ -103,7 +110,7 @@ __gconv_load_cache (void)
   __close (fd);
 
   /* Check the consistency.  */
-  header = (struct gconvcache_header *) __gconv_cache;
+  header = (struct gconvcache_header *) gconv_cache;
   if (__builtin_expect (header->magic, GCONVCACHE_MAGIC) != GCONVCACHE_MAGIC
       || __builtin_expect (header->string_offset >= cache_size, 0)
       || __builtin_expect (header->hash_offset >= cache_size, 0)
@@ -116,14 +123,14 @@ __gconv_load_cache (void)
     {
       if (cache_malloced)
 	{
-	  free (__gconv_cache);
+	  free (gconv_cache);
 	  cache_malloced = 0;
 	}
 #ifdef _POSIX_MAPPED_FILES
       else
-	__munmap (__gconv_cache, cache_size);
+	__munmap (gconv_cache, cache_size);
 #endif
-      __gconv_cache = NULL;
+      gconv_cache = NULL;
 
       return -1;
     }
@@ -145,9 +152,9 @@ find_module_idx (const char *str, size_t *idxp)
   const struct hash_entry *hashtab;
   unsigned int limit;
 
-  header = (const struct gconvcache_header *) __gconv_cache;
-  strtab = (char *) __gconv_cache + header->string_offset;
-  hashtab = (struct hash_entry *) ((char *) __gconv_cache
+  header = (const struct gconvcache_header *) gconv_cache;
+  strtab = (char *) gconv_cache + header->string_offset;
+  hashtab = (struct hash_entry *) ((char *) gconv_cache
 				   + header->hash_offset);
 
   hval = hash_string (str);
@@ -211,7 +218,7 @@ __gconv_compare_alias_cache (const char *name1, const char *name2, int *result)
   size_t name1_idx;
   size_t name2_idx;
 
-  if (__gconv_cache == NULL)
+  if (gconv_cache == NULL)
     return -1;
 
   if (find_module_idx (name1, &name1_idx) != 0
@@ -238,13 +245,13 @@ __gconv_lookup_cache (const char *toset, const char *fromset,
   const struct module_entry *to_module;
   struct __gconv_step *result;
 
-  if (__gconv_cache == NULL)
+  if (gconv_cache == NULL)
     /* We have no cache available.  */
     return __GCONV_NODB;
 
-  header = (const struct gconvcache_header *) __gconv_cache;
-  strtab = (char *) __gconv_cache + header->string_offset;
-  modtab = (const struct module_entry *) ((char *) __gconv_cache
+  header = (const struct gconvcache_header *) gconv_cache;
+  strtab = (char *) gconv_cache + header->string_offset;
+  modtab = (const struct module_entry *) ((char *) gconv_cache
 					  + header->module_offset);
 
   if (find_module_idx (fromset, &fromidx) != 0
@@ -273,7 +280,7 @@ __gconv_lookup_cache (const char *toset, const char *fromset,
 
       /* Note the -1.  This is due to the offset added in iconvconfig.
 	 See there for more explanations.  */
-      extra = (const struct extra_entry *) ((char *) __gconv_cache
+      extra = (const struct extra_entry *) ((char *) gconv_cache
 					    + header->otherconv_offset
 					    + from_module->extra_offset - 1);
       while (extra->module_cnt != 0
@@ -430,7 +437,7 @@ void
 internal_function
 __gconv_release_cache (struct __gconv_step *steps, size_t nsteps)
 {
-  if (__gconv_cache != NULL)
+  if (gconv_cache != NULL)
     /* The only thing we have to deallocate is the record with the
        steps.  */
     free (steps);
@@ -442,10 +449,10 @@ static void __attribute__ ((unused))
 free_mem (void)
 {
   if (cache_malloced)
-    free (__gconv_cache);
+    free (gconv_cache);
 #ifdef _POSIX_MAPPED_FILES
   else
-    __munmap (__gconv_cache, cache_size);
+    __munmap (gconv_cache, cache_size);
 #endif
 }
 
diff --git a/iconv/gconv_db.c b/iconv/gconv_db.c
index 9bd27c5e69..25b06d07e4 100644
--- a/iconv/gconv_db.c
+++ b/iconv/gconv_db.c
@@ -1,5 +1,5 @@
 /* Provide access to the collection of available transformation modules.
-   Copyright (C) 1997,98,99,2000,2001 Free Software Foundation, Inc.
+   Copyright (C) 1997,98,99,2000,2001,2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
 
@@ -41,6 +41,20 @@ struct gconv_module *__gconv_modules_db;
 __libc_lock_define_initialized (static, lock)
 
 
+/* Provide access to module database.  */
+struct gconv_module *
+__gconv_get_modules_db (void)
+{
+  return __gconv_modules_db;
+}
+
+void *
+__gconv_get_alias_db (void)
+{
+  return __gconv_alias_db;
+}
+
+
 /* Function for searching alias.  */
 int
 __gconv_alias_compare (const void *p1, const void *p2)
diff --git a/iconv/gconv_int.h b/iconv/gconv_int.h
index df7d2ee65f..a16a5434d7 100644
--- a/iconv/gconv_int.h
+++ b/iconv/gconv_int.h
@@ -114,11 +114,11 @@ enum
 /* Global variables.  */
 
 /* Database of alias names.  */
-extern void *__gconv_alias_db;
+extern void *__gconv_alias_db attribute_hidden;
 
 /* Array with available modules.  */
 extern size_t __gconv_nmodules;
-extern struct gconv_module *__gconv_modules_db;
+extern struct gconv_module *__gconv_modules_db attribute_hidden;
 
 /* Value of the GCONV_PATH environment variable.  */
 extern const char *__gconv_path_envvar attribute_hidden;
@@ -204,6 +204,15 @@ extern void __gconv_read_conf (void) attribute_hidden;
 /* Try to read module cache file.  */
 extern int __gconv_load_cache (void) internal_function;
 
+/* Retrieve pointer to internal cache.  */
+extern void *__gconv_get_cache (void);
+
+/* Retrieve pointer to internal module database.  */
+extern struct gconv_module *__gconv_get_modules_db (void);
+
+/* Retrieve pointer to internal alias database.  */
+extern void *__gconv_get_alias_db (void);
+
 /* Determine the directories we are looking in.  */
 extern void __gconv_get_path (void) internal_function;
 
diff --git a/iconv/iconv_prog.c b/iconv/iconv_prog.c
index f7aa340321..8a8535bf50 100644
--- a/iconv/iconv_prog.c
+++ b/iconv/iconv_prog.c
@@ -47,9 +47,6 @@
 #define PACKAGE _libc_intl_domainname
 
 
-/* Defined in gconv_cache.c.  */
-extern void *__gconv_cache;
-
 /* Name and version of program.  */
 static void print_version (FILE *stream, struct argp_state *state);
 void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version;
@@ -668,10 +665,9 @@ insert_cache (void)
   const struct hash_entry *hashtab;
   size_t cnt;
 
-  header = (const struct gconvcache_header *) __gconv_cache;
-  strtab = (char *) __gconv_cache + header->string_offset;
-  hashtab = (struct hash_entry *) ((char *) __gconv_cache
-				   + header->hash_offset);
+  header = (const struct gconvcache_header *) __gconv_get_cache ();
+  strtab = (char *) header + header->string_offset;
+  hashtab = (struct hash_entry *) ((char *) header + header->hash_offset);
 
   for (cnt = 0; cnt < header->hash_size; ++cnt)
     if (hashtab[cnt].string_offset != 0)
@@ -689,24 +685,29 @@ internal_function
 print_known_names (void)
 {
   iconv_t h;
+  void *cache;
 
   /* We must initialize the internal databases first.  */
   h = iconv_open ("L1", "L1");
   iconv_close (h);
 
   /* See whether we have a cache.  */
-  if (__gconv_cache != NULL)
+  cache = __gconv_get_cache ();
+  if (cache != NULL)
     /* Yep, use only this information.  */
     insert_cache ();
   else
     {
+      struct gconv_module *modules;
+
       /* No, then use the information read from the gconv-modules file.
 	 First add the aliases.  */
-      twalk (__gconv_alias_db, insert_print_list);
+      twalk (__gconv_get_alias_db (), insert_print_list);
 
       /* Add the from- and to-names from the known modules.  */
-      if (__gconv_modules_db != NULL)
-	add_known_names (__gconv_modules_db);
+      modules = __gconv_get_modules_db ();
+      if (modules != NULL)
+	add_known_names (modules);
     }
 
   fputs (_("\