From owner-svn-src-head@FreeBSD.ORG Sat May 25 12:13:55 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 6D9F431E; Sat, 25 May 2013 12:13:55 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 48055F01; Sat, 25 May 2013 12:13:55 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r4PCDtR6006760; Sat, 25 May 2013 12:13:55 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r4PCDtGu006759; Sat, 25 May 2013 12:13:55 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <201305251213.r4PCDtGu006759@svn.freebsd.org> From: Ed Schouten Date: Sat, 25 May 2013 12:13:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r250981 - head/lib/libc/iconv X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 25 May 2013 12:13:55 -0000 Author: ed Date: Sat May 25 12:13:54 2013 New Revision: 250981 URL: http://svnweb.freebsd.org/changeset/base/250981 Log: Make some tiny improvements to iconv_open(). - Remove an unneeded variable. - Fix whitespace bugs. - Fix typoes in comment. - Improve string handling a bit. Don't handroll strstr() and don't terminate a strdup()'ed string. Instead, simply strndup() the part we need. Modified: head/lib/libc/iconv/iconv.c Modified: head/lib/libc/iconv/iconv.c ============================================================================== --- head/lib/libc/iconv/iconv.c Sat May 25 12:11:20 2013 (r250980) +++ head/lib/libc/iconv/iconv.c Sat May 25 12:13:54 2013 (r250981) @@ -66,37 +66,31 @@ iconv_t _iconv_open(const char *out, c struct _citrus_iconv *prealloc); iconv_t -_iconv_open(const char *out, const char *in, struct _citrus_iconv *prealloc) +_iconv_open(const char *out, const char *in, struct _citrus_iconv *handle) { - struct _citrus_iconv *handle; - char *out_truncated, *p; + const char *out_slashes; + char *out_noslashes; int ret; - handle = prealloc; - /* * Remove anything following a //, as these are options (like * //ignore, //translate, etc) and we just don't handle them. - * This is for compatibilty with software that uses thees + * This is for compatibility with software that uses these * blindly. */ - out_truncated = strdup(out); - if (out_truncated == NULL) { - errno = ENOMEM; - return ((iconv_t)-1); + out_slashes = strstr(out, "//"); + if (out_slashes != NULL) { + out_noslashes = strndup(out, out_slashes - out); + if (out_noslashes == NULL) { + errno = ENOMEM; + return ((iconv_t)-1); + } + ret = _citrus_iconv_open(&handle, in, out_noslashes); + free(out_noslashes); + } else { + ret = _citrus_iconv_open(&handle, in, out); } - p = out_truncated; - while (*p != 0) { - if (p[0] == '/' && p[1] == '/') { - *p = '\0'; - break; - } - p++; - } - - ret = _citrus_iconv_open(&handle, in, out_truncated); - free(out_truncated); if (ret) { errno = ret == ENOENT ? EINVAL : ret; return ((iconv_t)-1);