diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2012-08-13 14:24:36 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2012-08-21 07:54:07 +1000 |
commit | 7f8c39c8b5ef89153ecd84d16331e96d8feb18ef (patch) | |
tree | 9be2f3af42f5d7dc074c10e4978ee34af358cf9f /os | |
parent | 36c1d92ec0ef0f3927034a12d4cb79dcc22bd185 (diff) |
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>
Diffstat (limited to 'os')
-rw-r--r-- | os/utils.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/os/utils.c b/os/utils.c index 947f8673a..04bcbc61f 100644 --- a/os/utils.c +++ b/os/utils.c @@ -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 |