Add __archive_strappend_int to format a decimal

number into a variable-length archive_string.
This commit is contained in:
kientzle 2004-12-22 06:12:40 +00:00
parent 2ae4fec062
commit c2a15e64c5
2 changed files with 19 additions and 0 deletions

View File

@ -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);
}

View File

@ -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);