summaryrefslogtreecommitdiffstats
path: root/lib/libarchive
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2004-12-22 06:12:40 +0000
committerkientzle <kientzle@FreeBSD.org>2004-12-22 06:12:40 +0000
commit1db0b0f050e30839db90f83be87d7bd5e17c9141 (patch)
tree3352f7af4c1f4823ef2f4f281aeced2eb8e49585 /lib/libarchive
parent5babdbc5e39772bd06d90df99bca82383176306c (diff)
downloadFreeBSD-src-1db0b0f050e30839db90f83be87d7bd5e17c9141.zip
FreeBSD-src-1db0b0f050e30839db90f83be87d7bd5e17c9141.tar.gz
Add __archive_strappend_int to format a decimal
number into a variable-length archive_string.
Diffstat (limited to 'lib/libarchive')
-rw-r--r--lib/libarchive/archive_string.c15
-rw-r--r--lib/libarchive/archive_string.h4
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/libarchive/archive_string.c b/lib/libarchive/archive_string.c
index 0e92836..b18f31d 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 79597df..f4e8b76 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);
OpenPOWER on IntegriCloud