Add FormatInt64 to convert signed integers in signal-safe manner

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Chase Douglas <chase.douglas@canonical.com>
This commit is contained in:
Peter Hutterer
2012-08-13 14:24:36 +10:00
parent 36c1d92ec0
commit 7f8c39c8b5
3 changed files with 92 additions and 3 deletions

View File

@@ -1924,6 +1924,20 @@ xstrtokenize(const char *str, const char *separators)
return NULL;
}
/* Format a signed number into a string in a signal safe manner. The string
* should be at least 21 characters in order to handle all int64_t values.
*/
void
FormatInt64(int64_t num, char *string)
{
if (num < 0) {
string[0] = '-';
num *= -1;
string++;
}
FormatUInt64(num, string);
}
/* Format a number into a string in a signal safe manner. The string should be
* at least 21 characters in order to handle all uint64_t values. */
void