Index: glib/gconvert.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gconvert.c,v
retrieving revision 1.74
diff -u -r1.74 gconvert.c
--- glib/gconvert.c	27 Apr 2005 09:50:08 -0000	1.74
+++ glib/gconvert.c	1 Aug 2005 20:39:05 -0000
@@ -569,7 +569,7 @@
 {
   gchar *dest;
   gchar *outp;
-  const gchar *p;
+  const gchar *p, *inp;
   gsize inbytes_remaining;
   gsize outbytes_remaining;
   gsize err;
@@ -582,7 +582,7 @@
   if (len < 0)
     len = strlen (str);
 
-  p = str;
+  inp = str;
   inbytes_remaining = len;
   outbuf_size = len + 1; /* + 1 for nul in case len == 1 */
   
@@ -591,10 +591,11 @@
 
  again:
   
-  err = g_iconv (converter, (char **)&p, &inbytes_remaining, &outp, &outbytes_remaining);
+  err = g_iconv (converter, (char **)&inp, &inbytes_remaining, &outp, &outbytes_remaining);
 
   if (err == (size_t) -1)
     {
+      p = inp;
       switch (errno)
 	{
 	case EINVAL:
@@ -627,7 +628,14 @@
 	  break;
 	}
     }
-
+  else if (inp)
+    {
+      p = inp;
+      inp = NULL;
+      
+      goto again;
+    }
+  
   *outp = '\0';
   
   if (bytes_read)
@@ -856,6 +864,34 @@
 	    }
 	  else
 	    done = TRUE;
+	}
+    }
+
+  if (!have_error)
+    {
+      size_t inbytes_tmp;
+
+    again:
+
+      inbytes_tmp = 0;
+      err = g_iconv (cd, NULL, &inbytes_tmp, &outp, &outbytes_remaining);
+      
+      if (err == (size_t) -1)
+	{
+	  if (errno == E2BIG)
+	    {
+	      size_t used = outp - dest;
+	      
+	      outbuf_size *= 2;
+	      dest = g_realloc (dest, outbuf_size);
+	      
+	      outp = dest + used;
+	      outbytes_remaining = outbuf_size - used - 1; /* -1 for nul */
+	      
+	      goto again;
+	    }
+	  else
+	    have_error = TRUE;
 	}
     }
 
