parse_bytes function more graceful
parent
76ef22d380
commit
f37c3bf013
3
HISTORY
3
HISTORY
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
Version 1.49 2021-04-09
|
Version 1.49 2021-04-17
|
||||||
* add macros: FC_ABS and FC_NEGATIVE
|
* add macros: FC_ABS and FC_NEGATIVE
|
||||||
* uniq_skiplist.c: add uniq_skiplist_pair struct and init function
|
* uniq_skiplist.c: add uniq_skiplist_pair struct and init function
|
||||||
* add functions: fc_mkdirs and str_replace
|
* add functions: fc_mkdirs and str_replace
|
||||||
|
|
@ -8,6 +8,7 @@ Version 1.49 2021-04-09
|
||||||
* add function: fc_check_filename_ex
|
* add function: fc_check_filename_ex
|
||||||
* add functions: fc_queue_push_queue_to_tail etc.
|
* add functions: fc_queue_push_queue_to_tail etc.
|
||||||
* add file locked_list.h
|
* add file locked_list.h
|
||||||
|
* parse_bytes function more graceful
|
||||||
|
|
||||||
Version 1.48 2021-02-01
|
Version 1.48 2021-02-01
|
||||||
* fast_buffer.[hc]: add function fast_buffer_append_binary
|
* fast_buffer.[hc]: add function fast_buffer_append_binary
|
||||||
|
|
|
||||||
|
|
@ -2172,46 +2172,67 @@ int cmp_by_ip_addr_t(const void *p1, const void *p2)
|
||||||
int parse_bytes(const char *pStr, const int default_unit_bytes, int64_t *bytes)
|
int parse_bytes(const char *pStr, const int default_unit_bytes, int64_t *bytes)
|
||||||
{
|
{
|
||||||
char *pReservedEnd;
|
char *pReservedEnd;
|
||||||
|
int result;
|
||||||
|
|
||||||
pReservedEnd = NULL;
|
pReservedEnd = NULL;
|
||||||
*bytes = strtol(pStr, &pReservedEnd, 10);
|
*bytes = strtol(pStr, &pReservedEnd, 10);
|
||||||
if (*bytes < 0)
|
if (*bytes < 0)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, " \
|
||||||
"bytes: %"PRId64" < 0, input string: %s",
|
"bytes: %"PRId64" < 0, input string: %s",
|
||||||
__LINE__, *bytes, pStr);
|
__LINE__, *bytes, pStr);
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pReservedEnd == NULL || *pReservedEnd == '\0')
|
if (pReservedEnd == NULL || *pReservedEnd == '\0')
|
||||||
{
|
{
|
||||||
*bytes *= default_unit_bytes;
|
*bytes *= default_unit_bytes;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
else if (*pReservedEnd == 'T' || *pReservedEnd == 't')
|
|
||||||
|
if (*pReservedEnd == 'T' || *pReservedEnd == 't')
|
||||||
{
|
{
|
||||||
*bytes *= 1024 * 1024 * 1024 * 1024LL;
|
*bytes *= 1024 * 1024 * 1024 * 1024LL;
|
||||||
|
result = 0;
|
||||||
}
|
}
|
||||||
else if (*pReservedEnd == 'G' || *pReservedEnd == 'g')
|
else if (*pReservedEnd == 'G' || *pReservedEnd == 'g')
|
||||||
{
|
{
|
||||||
*bytes *= 1024 * 1024 * 1024;
|
*bytes *= 1024 * 1024 * 1024;
|
||||||
|
result = 0;
|
||||||
}
|
}
|
||||||
else if (*pReservedEnd == 'M' || *pReservedEnd == 'm')
|
else if (*pReservedEnd == 'M' || *pReservedEnd == 'm')
|
||||||
{
|
{
|
||||||
*bytes *= 1024 * 1024;
|
*bytes *= 1024 * 1024;
|
||||||
|
result = 0;
|
||||||
}
|
}
|
||||||
else if (*pReservedEnd == 'K' || *pReservedEnd == 'k')
|
else if (*pReservedEnd == 'K' || *pReservedEnd == 'k')
|
||||||
{
|
{
|
||||||
*bytes *= 1024;
|
*bytes *= 1024;
|
||||||
}
|
result = 0;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, "
|
result = EINVAL;
|
||||||
"unkown byte unit: %c (0x%02x), input string: %s",
|
|
||||||
__LINE__, *pReservedEnd, *pReservedEnd, pStr);
|
|
||||||
return EINVAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
if (result == 0)
|
||||||
|
{
|
||||||
|
if (*(pReservedEnd + 1) == '\0')
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if ((*(pReservedEnd + 1) == 'B' || *(pReservedEnd + 1) == 'b') &&
|
||||||
|
(*(pReservedEnd + 2) == '\0'))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
result = EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
logError("file: "__FILE__", line: %d, "
|
||||||
|
"unkown byte unit: %s, input string: %s",
|
||||||
|
__LINE__, pReservedEnd, pStr);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int set_rand_seed()
|
int set_rand_seed()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue