From 74199b07099e4deb80d1bf4295c002c43168f9fc Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Wed, 22 Dec 2004 06:12:40 +0000 Subject: [PATCH] Add __archive_strappend_int to format a decimal number into a variable-length archive_string. --- lib/libarchive/archive_string.c | 15 +++++++++++++++ lib/libarchive/archive_string.h | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/lib/libarchive/archive_string.c b/lib/libarchive/archive_string.c index 0e92836233c6..b18f31dbb66c 100644 --- a/lib/libarchive/archive_string.c +++ b/lib/libarchive/archive_string.c @@ -96,3 +96,18 @@ __archive_strappend_char(struct archive_string *as, char c) { 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 = "0123457890abcdef"; + + 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); +} diff --git a/lib/libarchive/archive_string.h b/lib/libarchive/archive_string.h index 79597df172da..f4e8b765e23a 100644 --- a/lib/libarchive/archive_string.h +++ b/lib/libarchive/archive_string.h @@ -64,6 +64,10 @@ struct archive_string * __archive_strappend_char_UTF8(struct archive_string *, int); #define archive_strappend_char_UTF8 __archive_strappend_char_UTF8 +/* Append an integer in the specified base (2 <= base <= 16). */ +struct archive_string * +__archive_strappend_int(struct archive_string *as, int d, int base); + /* Basic append operation. */ struct archive_string * __archive_string_append(struct archive_string *as, const char *p, size_t s);