From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4471 invoked by alias); 3 Sep 2005 09:04:49 -0000 Mailing-List: contact glibc-bugs-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-owner@sources.redhat.com Received: (qmail 4435 invoked by uid 48); 3 Sep 2005 09:04:42 -0000 Date: Sat, 03 Sep 2005 09:04:00 -0000 From: "simon at josefsson dot org" To: glibc-bugs@sources.redhat.com Message-ID: <20050903090440.1293.simon@josefsson.org> Reply-To: sourceware-bugzilla@sources.redhat.com Subject: [Bug libc/1293] New: libidn/iconvme.c improvement for gnulib X-Bugzilla-Reason: CC X-SW-Source: 2005-09/txt/msg00027.txt.bz2 List-Id: 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" + + * iconvme.h: Add prototype for iconv_alloc. + +2005-08-29 Simon Josefsson + + * iconvme.c: Fix errno. + +2005-08-29 "Oskar Liljeblad" + + * iconvme.c: Split iconv_string into iconv_alloc. + 2005-03-08 Paul Eggert * 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 @@ -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 +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.