]> Savannah Git Hosting - gnulib.git/commitdiff
(iconv_string): No need to save and restore errno when iconv_alloc succeeded.
authorBruno Haible <bruno@clisp.org>
Tue, 5 Sep 2006 11:45:14 +0000 (11:45 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 5 Sep 2006 11:45:14 +0000 (11:45 +0000)
lib/iconvme.c

index 943380c03554bc90322eb9dd46a608df4e59e57c..0e3d7b5ccd7954da72fa0faa8f53a30a030ef45d 100644 (file)
@@ -75,21 +75,24 @@ iconv_string (const char *str, const char *from_codeset,
 
   dest = iconv_alloc (cd, str);
 
-  {
-    int save_errno = errno;
-
-    if (iconv_close (cd) < 0 && dest)
-      {
-       int save_errno2 = errno;
-       /* If we didn't have a real error before, make sure we restore
-          the iconv_close error below. */
-       free (dest);
-       dest = NULL;
-       errno = save_errno2;
-      }
-    else
-      errno = save_errno;
-  }
+  if (dest == NULL)
+    {
+      int saved_errno = errno;
+      iconv_close (cd);
+      errno = saved_errno;
+    }
+  else
+    {
+      if (iconv_close (cd) < 0)
+       {
+         int saved_errno2 = errno;
+         /* If we didn't have a real error before, make sure we restore
+            the iconv_close error below. */
+         free (dest);
+         dest = NULL;
+         errno = saved_errno2;
+       }
+    }
 #else
   errno = ENOSYS;
 #endif