public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/1293] New: libidn/iconvme.c improvement for gnulib
@ 2005-09-03  9:04 simon at josefsson dot org
  2005-09-07 19:34 ` [Bug libc/1293] " eggert at gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: simon at josefsson dot org @ 2005-09-03  9:04 UTC (permalink / raw)
  To: glibc-bugs

Hi.  libidn/iconvme.* is used by gnulib, and we got a patch to improve
functionality of the iconvme module.  The following merge this back into glibc,
so gnulib can continue to be synchronized with glibc sources.

Thanks!

cvs diff: Diffing .
Index: ChangeLog
===================================================================
RCS file: /cvs/glibc/libc/libidn/ChangeLog,v
retrieving revision 1.14
diff -u -p -r1.14 ChangeLog
--- ChangeLog   15 Mar 2005 22:21:12 -0000      1.14
+++ ChangeLog   3 Sep 2005 09:03:48 -0000
@@ -1,3 +1,15 @@
+2005-08-30  "Oskar Liljeblad" <oskar@osk.mine.nu>
+
+       * iconvme.h: Add prototype for iconv_alloc.
+
+2005-08-29  Simon Josefsson  <jas@extundo.com>
+
+       * iconvme.c: Fix errno.
+
+2005-08-29  "Oskar Liljeblad" <oskar@osk.mine.nu>
+
+       * iconvme.c: Split iconv_string into iconv_alloc.
+
 2005-03-08  Paul Eggert  <eggert@cs.ucla.edu>

        * iconvme.c (SIZE_MAX): New macro, if not already defined.
Index: iconvme.c
===================================================================
RCS file: /cvs/glibc/libc/libidn/iconvme.c,v
retrieving revision 1.2
diff -u -p -r1.2 iconvme.c
--- iconvme.c   15 Mar 2005 22:21:08 -0000      1.2
+++ iconvme.c   3 Sep 2005 09:03:48 -0000
@@ -1,10 +1,10 @@
 /* Recode strings between character sets, using iconv.
    Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.

-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public License as
-   published by the Free Software Foundation; either version 2.1, or (at
-   your option) any later version.
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1, or (at your option)
+   any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,7 +13,7 @@

    You should have received a copy of the GNU Lesser General Public License along
    with this program; if not, write to the Free Software Foundation,
-   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */

 #ifdef HAVE_CONFIG_H
 # include <config.h>
@@ -63,8 +63,54 @@ iconv_string (const char *str, const cha
   char *dest = NULL;
 #if HAVE_ICONV
   iconv_t cd;
-  char *outp;
+#endif
+
+  if (strcmp (to_codeset, from_codeset) == 0)
+    return strdup (str);
+
+#if HAVE_ICONV
+  cd = iconv_open (to_codeset, from_codeset);
+  if (cd == (iconv_t) -1)
+    return NULL;
+
+  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;
+  }
+#else
+  errno = ENOSYS;
+#endif
+
+  return dest;
+}
+
+/* Convert a zero-terminated string STR using iconv descriptor CD.
+   The returned string is allocated using malloc, and must be
+   dellocated by the caller using free.  On failure, NULL is returned
+   and errno holds the error reason.  Note that if the target
+   character set uses \0 for anything but to terminate the string,
+   the caller of this function may have difficulties finding
+   out the length of the output string.  */
+#if HAVE_ICONV
+char *
+iconv_alloc (iconv_t cd, const char *str)
+{
+  char *dest;
   char *p = (char *) str;
+  char *outp;
   size_t inbytes_remaining = strlen (p);
   /* Guess the maximum length the output string can have.  */
   size_t outbuf_size = inbytes_remaining + 1;
@@ -79,24 +125,15 @@ iconv_string (const char *str, const cha
   if (outbuf_size <= approx_sqrt_SIZE_MAX / MB_LEN_MAX)
     outbuf_size *= MB_LEN_MAX;
   outbytes_remaining = outbuf_size - 1;
-#endif
-
-  if (strcmp (to_codeset, from_codeset) == 0)
-    return strdup (str);
-
-#if HAVE_ICONV
-  cd = iconv_open (to_codeset, from_codeset);
-  if (cd == (iconv_t) -1)
-    return NULL;

   outp = dest = (char *) malloc (outbuf_size);
   if (dest == NULL)
-    goto out;
+    return NULL;

 again:
   err = iconv (cd, &p, &inbytes_remaining, &outp, &outbytes_remaining);

-  if (err == (size_t) - 1)
+  if (err == (size_t) -1)
     {
       switch (errno)
        {
@@ -145,27 +182,14 @@ again:
   *outp = '\0';

 out:
-  {
-    int save_errno = errno;
-
-    if (iconv_close (cd) < 0 && !have_error)
-      {
-       /* If we didn't have a real error before, make sure we restore
-          the iconv_close error below. */
-       save_errno = errno;
-       have_error = 1;
-      }
-
-    if (have_error && dest)
-      {
-       free (dest);
-       dest = NULL;
-       errno = save_errno;
-      }
-  }
-#else
-  errno = ENOSYS;
-#endif
+  if (have_error && dest)
+    {
+      int save_errno = errno;
+      free(dest);
+      errno = save_errno;
+      dest = NULL;
+    }

   return dest;
 }
+#endif
Index: iconvme.h
===================================================================
RCS file: /cvs/glibc/libc/libidn/iconvme.h,v
retrieving revision 1.1
diff -u -p -r1.1 iconvme.h
--- iconvme.h   22 Feb 2005 01:24:52 -0000      1.1
+++ iconvme.h   3 Sep 2005 09:03:48 -0000
@@ -12,9 +12,9 @@
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

-   You should have received a copy of the GNU Lesser General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */

 #ifndef ICONVME_H
 # define ICONVME_H
@@ -22,4 +22,9 @@
 extern char *iconv_string (const char *string, const char *from_code,
                           const char *to_code);

+#if HAVE_ICONV
+# include <iconv.h>
+extern char *iconv_alloc (iconv_t cd, const char *string);
+#endif
+
 #endif /* ICONVME_H */

-- 
           Summary: libidn/iconvme.c improvement for gnulib
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: libc
        AssignedTo: gotom at debian dot or dot jp
        ReportedBy: simon at josefsson dot org
                CC: glibc-bugs at sources dot redhat dot com


http://sources.redhat.com/bugzilla/show_bug.cgi?id=1293

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libc/1293] libidn/iconvme.c improvement for gnulib
  2005-09-03  9:04 [Bug libc/1293] New: libidn/iconvme.c improvement for gnulib simon at josefsson dot org
@ 2005-09-07 19:34 ` eggert at gnu dot org
  2005-09-08  7:32 ` roland at gnu dot org
  2006-04-25 18:22 ` drepper at redhat dot com
  2 siblings, 0 replies; 4+ messages in thread
From: eggert at gnu dot org @ 2005-09-07 19:34 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From eggert at gnu dot org  2005-09-07 19:33 -------
Created an attachment (id=654)
 --> (http://sourceware.org/bugzilla/attachment.cgi?id=654&action=view)
Don't reformat the reference to the LGPL

The original patch reformatted the paragraphs of the LGPL reference.
This isn't needed.  Here's the same patch again, with the LGPL reference
left unchanged.

-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=1293

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libc/1293] libidn/iconvme.c improvement for gnulib
  2005-09-03  9:04 [Bug libc/1293] New: libidn/iconvme.c improvement for gnulib simon at josefsson dot org
  2005-09-07 19:34 ` [Bug libc/1293] " eggert at gnu dot org
@ 2005-09-08  7:32 ` roland at gnu dot org
  2006-04-25 18:22 ` drepper at redhat dot com
  2 siblings, 0 replies; 4+ messages in thread
From: roland at gnu dot org @ 2005-09-08  7:32 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From roland at gnu dot org  2005-09-08 07:32 -------
Describe how this improves the module.
The patch has some formatting typos like missing space before paren.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |WAITING


http://sourceware.org/bugzilla/show_bug.cgi?id=1293

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libc/1293] libidn/iconvme.c improvement for gnulib
  2005-09-03  9:04 [Bug libc/1293] New: libidn/iconvme.c improvement for gnulib simon at josefsson dot org
  2005-09-07 19:34 ` [Bug libc/1293] " eggert at gnu dot org
  2005-09-08  7:32 ` roland at gnu dot org
@ 2006-04-25 18:22 ` drepper at redhat dot com
  2 siblings, 0 replies; 4+ messages in thread
From: drepper at redhat dot com @ 2006-04-25 18:22 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From drepper at redhat dot com  2006-04-25 18:22 -------
No response in 6+ months.  Closing.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|                            |WONTFIX


http://sourceware.org/bugzilla/show_bug.cgi?id=1293

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-04-25 18:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-03  9:04 [Bug libc/1293] New: libidn/iconvme.c improvement for gnulib simon at josefsson dot org
2005-09-07 19:34 ` [Bug libc/1293] " eggert at gnu dot org
2005-09-08  7:32 ` roland at gnu dot org
2006-04-25 18:22 ` drepper at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).