From owner-svn-src-all@FreeBSD.ORG Fri Mar 6 05:14:55 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C0EC41065674; Fri, 6 Mar 2009 05:14:55 +0000 (UTC) (envelope-from kientzle@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id AE03F8FC1D; Fri, 6 Mar 2009 05:14:55 +0000 (UTC) (envelope-from kientzle@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n265EtA2009050; Fri, 6 Mar 2009 05:14:55 GMT (envelope-from kientzle@svn.freebsd.org) Received: (from kientzle@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n265Etn3009047; Fri, 6 Mar 2009 05:14:55 GMT (envelope-from kientzle@svn.freebsd.org) Message-Id: <200903060514.n265Etn3009047@svn.freebsd.org> From: Tim Kientzle Date: Fri, 6 Mar 2009 05:14:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r189435 - head/lib/libarchive X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Mar 2009 05:14:57 -0000 Author: kientzle Date: Fri Mar 6 05:14:55 2009 New Revision: 189435 URL: http://svn.freebsd.org/changeset/base/189435 Log: Merge r505 from libarchive.googlecode.com: Fix %ju support. Simplify the code here a bit by making the int formatting functions static to archive_string_sprintf.c, which is the only place this has ever been used. Modified: head/lib/libarchive/archive_string.c head/lib/libarchive/archive_string.h head/lib/libarchive/archive_string_sprintf.c Modified: head/lib/libarchive/archive_string.c ============================================================================== --- head/lib/libarchive/archive_string.c Fri Mar 6 05:13:12 2009 (r189434) +++ head/lib/libarchive/archive_string.c Fri Mar 6 05:14:55 2009 (r189435) @@ -163,21 +163,6 @@ __archive_strappend_char(struct archive_ return (__archive_string_append(as, &c, 1)); } -struct archive_string * -__archive_strappend_int(struct archive_string *as, int d, int base) -{ - static const char *digits = "0123456789abcdef"; - - if (d < 0) { - __archive_strappend_char(as, '-'); - d = -d; - } - if (d >= base) - __archive_strappend_int(as, d/base, base); - __archive_strappend_char(as, digits[d % base]); - return (as); -} - #ifndef _WIN32 /* * Home-grown wctomb for UTF-8. Modified: head/lib/libarchive/archive_string.h ============================================================================== --- head/lib/libarchive/archive_string.h Fri Mar 6 05:13:12 2009 (r189434) +++ head/lib/libarchive/archive_string.h Fri Mar 6 05:14:55 2009 (r189435) @@ -66,11 +66,6 @@ struct archive_string * __archive_strappend_char(struct archive_string *, char); #define archive_strappend_char __archive_strappend_char -/* Append an integer in the specified base (2 <= base <= 16). */ -struct archive_string * -__archive_strappend_int(struct archive_string *as, int d, int base); -#define archive_strappend_int __archive_strappend_int - /* Convert a wide-char string to UTF-8 and append the result. */ struct archive_string * __archive_strappend_w_utf8(struct archive_string *, const wchar_t *); Modified: head/lib/libarchive/archive_string_sprintf.c ============================================================================== --- head/lib/libarchive/archive_string_sprintf.c Fri Mar 6 05:13:12 2009 (r189434) +++ head/lib/libarchive/archive_string_sprintf.c Fri Mar 6 05:14:55 2009 (r189435) @@ -32,7 +32,7 @@ __FBSDID("$FreeBSD$"); * implementing this function in terms of vsnprintf() requires * two calls (one to determine the size, another to format the * result), which in turn requires duplicating the argument list - * using va_copy, which isn't yet universally available. + * using va_copy, which isn't yet universally available. * * So, I've implemented a bare minimum of printf()-like capability * here. This is only used to format error messages, so doesn't @@ -44,6 +44,30 @@ __FBSDID("$FreeBSD$"); #include "archive_string.h" #include "archive_private.h" +/* + * Utility functions to format signed/unsigned integers and append + * them to an archive_string. + */ +static void +append_uint(struct archive_string *as, uintmax_t d, unsigned base) +{ + static const char *digits = "0123456789abcdef"; + if (d >= base) + append_uint(as, d/base, base); + archive_strappend_char(as, digits[d % base]); +} + +static void +append_int(struct archive_string *as, intmax_t d, unsigned base) +{ + if (d < 0) { + archive_strappend_char(as, '-'); + d = -d; + } + append_uint(as, d, base); +} + + void __archive_string_sprintf(struct archive_string *as, const char *fmt, ...) { @@ -75,7 +99,6 @@ __archive_string_vsprintf(struct archive return; } - long_flag = '\0'; for (p = fmt; *p != '\0'; p++) { const char *saved_p = p; @@ -86,6 +109,7 @@ __archive_string_vsprintf(struct archive p++; + long_flag = '\0'; switch(*p) { case 'j': long_flag = 'j'; @@ -111,7 +135,7 @@ __archive_string_vsprintf(struct archive case 'l': s = va_arg(ap, long); break; default: s = va_arg(ap, int); break; } - archive_strappend_int(as, s, 10); + append_int(as, s, 10); break; case 's': p2 = va_arg(ap, char *); @@ -126,9 +150,9 @@ __archive_string_vsprintf(struct archive } /* Format it in the correct base. */ switch (*p) { - case 'o': archive_strappend_int(as, u, 8); break; - case 'u': archive_strappend_int(as, u, 10); break; - default: archive_strappend_int(as, u, 16); break; + case 'o': append_uint(as, u, 8); break; + case 'u': append_uint(as, u, 10); break; + default: append_uint(as, u, 16); break; } break; default: