about summary refs log tree commit diff
path: root/iconv/strtab.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2001-09-05 00:26:04 +0000
committerUlrich Drepper <drepper@redhat.com>2001-09-05 00:26:04 +0000
commit71ce28fd1abbccc9814d199d770e673135a33ee1 (patch)
tree2a57d3f2cb75d8261f720f7f4b967ec456248363 /iconv/strtab.c
parent903244ac3c697bc1f05c0ec0b994d7c36763ca3f (diff)
downloadglibc-71ce28fd1abbccc9814d199d770e673135a33ee1.tar.gz
glibc-71ce28fd1abbccc9814d199d770e673135a33ee1.tar.xz
glibc-71ce28fd1abbccc9814d199d770e673135a33ee1.zip
Update.
2001-09-04  Jakub Jelinek  <jakub@redhat.com>

	* iconv/strtab.c (strtabinit): Initialize null Strent.
	(newstring): Move len == 0 handling...
	(strtabadd): ...here.
	If len == 1, return null Strent.
	When inserting a suffix of an existing string, check if
	it is not equal to some suffix already recorded.
	Copy left and right members over if adding longer string.

2001-09-04  Jakub Jelinek  <jakub@redhat.com>

	* sunrpc/rpc_cout.c (upcase): Account for trailing '\0'.

	* sysdeps/unix/sysv/linux/alpha/gethostname.c: Include <errno.h>.
	(__syscall_gethostname): Add prototype.
Diffstat (limited to 'iconv/strtab.c')
-rw-r--r--iconv/strtab.c37
1 files changed, 32 insertions, 5 deletions
diff --git a/iconv/strtab.c b/iconv/strtab.c
index 4189f97281..e6feb2cf24 100644
--- a/iconv/strtab.c
+++ b/iconv/strtab.c
@@ -90,13 +90,21 @@ extern size_t strtaboffset (struct Strent *se);
 struct Strtab *
 strtabinit (void)
 {
+  struct Strtab *ret;
+
   if (ps == 0)
     {
       ps = sysconf (_SC_PAGESIZE) - 2 * sizeof (void *);
       assert (sizeof (struct memoryblock) < ps);
     }
 
-  return (struct Strtab *) calloc (1, sizeof (struct Strtab));
+  ret = (struct Strtab *) calloc (1, sizeof (struct Strtab));
+  if (ret != NULL)
+    {
+      ret->null.len = 1;
+      ret->null.string = "";
+    }
+  return ret;
 }
 
 
@@ -141,10 +149,6 @@ newstring (struct Strtab *st, const char *str, size_t len)
   size_t align;
   int i;
 
-  /* Compute the string length if the caller doesn't know it.  */
-  if (len == 0)
-    len = strlen (str) + 1;
-
   /* Compute the amount of padding needed to make the structure aligned.  */
   align = ((__alignof__ (struct Strent)
 	    - (((uintptr_t) st->backp)
@@ -211,6 +215,14 @@ strtabadd (struct Strtab *st, const char *str, size_t len)
   struct Strent *newstr;
   struct Strent **sep;
 
+  /* Compute the string length if the caller doesn't know it.  */
+  if (len == 0)
+    len = strlen (str) + 1;
+
+  /* Make sure all "" strings get offset 0.  */
+  if (len == 1)
+    return &st->null;
+
   /* Allocate memory for the new string and its associated information.  */
   newstr = newstring (st, str, len);
 
@@ -223,6 +235,19 @@ strtabadd (struct Strtab *st, const char *str, size_t len)
       /* This is not the same entry.  This means we have a prefix match.  */
       if ((*sep)->len > newstr->len)
 	{
+	  struct Strent *subs;
+
+	  for (subs = (*sep)->next; subs; subs = subs->next)
+	    if (subs->len == newstr->len)
+	      {
+		/* We have an exact match with a substring.  Free the memory
+		   we allocated.  */
+		st->left += st->backp - (char *) newstr;
+		st->backp = (char *) newstr;
+
+		return subs;
+	      }
+
 	  /* We have a new substring.  This means we don't need the reverse
 	     string of this entry anymore.  */
 	  st->backp -= newstr->len;
@@ -238,6 +263,8 @@ strtabadd (struct Strtab *st, const char *str, size_t len)
 	     it is longer.  In this case we have to put it first.  */
 	  st->total += newstr->len - (*sep)->len;
 	  newstr->next = *sep;
+	  newstr->left = (*sep)->left;
+	  newstr->right = (*sep)->right;
 	  *sep = newstr;
 	}
       else