diff options
author | kientzle <kientzle@FreeBSD.org> | 2004-12-22 06:12:40 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2004-12-22 06:12:40 +0000 |
commit | 1db0b0f050e30839db90f83be87d7bd5e17c9141 (patch) | |
tree | 3352f7af4c1f4823ef2f4f281aeced2eb8e49585 /lib/libarchive/archive_string.c | |
parent | 5babdbc5e39772bd06d90df99bca82383176306c (diff) | |
download | FreeBSD-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/archive_string.c')
-rw-r--r-- | lib/libarchive/archive_string.c | 15 |
1 files changed, 15 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); +} |