fix uhub_itoa() and uhub_ulltoa()
This commit is contained in:
parent
eb49174ab3
commit
8365278cbf
@ -73,6 +73,7 @@
|
||||
#include <time.h>
|
||||
|
||||
#if !defined(WIN32)
|
||||
#include <inttypes.h>
|
||||
#include <unistd.h>
|
||||
#include <grp.h>
|
||||
#include <pwd.h>
|
||||
|
@ -303,47 +303,19 @@ int is_number(const char* value, int* num)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* FIXME: -INTMIN is wrong!
|
||||
*/
|
||||
const char* uhub_itoa(int val)
|
||||
{
|
||||
size_t i;
|
||||
int value;
|
||||
static char buf[22];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
if (!val)
|
||||
{
|
||||
buf[0] = '0';
|
||||
buf[1] = '\0';
|
||||
return buf;
|
||||
}
|
||||
i = sizeof(buf) - 1;
|
||||
for (value = abs(val); value && i > 0; value /= 10)
|
||||
buf[--i] = "0123456789"[value % 10];
|
||||
|
||||
if (val < 0 && i > 0)
|
||||
buf[--i] = '-';
|
||||
return buf+i;
|
||||
return snprintf(buf, sizeof(buf), "%d", val) < 0 ? NULL : buf;
|
||||
}
|
||||
|
||||
|
||||
const char* uhub_ulltoa(uint64_t val)
|
||||
{
|
||||
size_t i;
|
||||
static char buf[22] = { 0, };
|
||||
memset(buf, 0, sizeof(buf));
|
||||
static char buf[22];
|
||||
|
||||
if (!val)
|
||||
{
|
||||
buf[0] = '0';
|
||||
buf[1] = '\0';
|
||||
return buf;
|
||||
}
|
||||
i = sizeof(buf) - 1;
|
||||
for (; val && i > 0; val /= 10)
|
||||
buf[--i] = "0123456789"[val % 10];
|
||||
return buf+i;
|
||||
return snprintf(buf, sizeof(buf), "%"PRIu64, val) < 0 ? NULL : buf;
|
||||
}
|
||||
|
||||
|
||||
|
@ -53,7 +53,11 @@ extern int file_read_lines(const char* file, void* data, file_line_handler_t han
|
||||
*/
|
||||
extern int string_to_boolean(const char* str, int* boolean);
|
||||
|
||||
|
||||
/**
|
||||
* Convert number to string.
|
||||
* Note: these functions are neither thread-safe nor reentrant.
|
||||
* @return pointer to the resulting string, NULL on error
|
||||
*/
|
||||
extern const char* uhub_itoa(int val);
|
||||
extern const char* uhub_ulltoa(uint64_t val);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user