(to_decimal): New function.

(xheader_format_name): Use to_decimal() instead of snprintf.
This commit is contained in:
Sergey Poznyakoff
2004-03-22 09:17:18 +00:00
parent e5882c8220
commit 6bd7b64c78

View File

@@ -191,6 +191,26 @@ xheader_set_option (char *string)
} }
} }
static void
to_decimal (uintmax_t value, char *where, size_t size)
{
size_t i = 0, j;
where[i++] = 0;
do
{
where[i++] = '0' + value % 10;
value /= 10;
}
while (i < size && value);
for (j = 0, i--; j < i; j++, i--)
{
char c = where[j];
where[j] = where[i];
where[i] = c;
}
}
/* /*
string Includes: Replaced By: string Includes: Replaced By:
%d The directory name of the file, %d The directory name of the file,
@@ -241,16 +261,14 @@ xheader_format_name (struct tar_stat_info *st, const char *fmt, bool allow_n)
break; break;
case 'p': case 'p':
snprintf (pidbuf, sizeof pidbuf, "%lu", to_decimal (getpid (), pidbuf, sizeof pidbuf);
(unsigned long) getpid ());
len += strlen (pidbuf) - 1; len += strlen (pidbuf) - 1;
break; break;
case 'n': case 'n':
if (allow_n) if (allow_n)
{ {
snprintf (nbuf, sizeof nbuf, "%lu", to_decimal (global_header_count + 1, pidbuf, sizeof pidbuf);
(unsigned long) global_header_count + 1);
len += strlen (nbuf) - 1; len += strlen (nbuf) - 1;
} }
break; break;