parse_bytes support space charactors
parent
8ab3420bce
commit
fd8fbfe644
3
HISTORY
3
HISTORY
|
|
@ -1,7 +1,8 @@
|
||||||
|
|
||||||
Version 1.65 2022-12-30
|
Version 1.65 2023-01-04
|
||||||
* locked_list.h: add functions locked_list_move and locked_list_move_tail
|
* locked_list.h: add functions locked_list_move and locked_list_move_tail
|
||||||
* add function tcp_socket_connected
|
* add function tcp_socket_connected
|
||||||
|
* parse_bytes support space charactors (before and after the unit)
|
||||||
|
|
||||||
Version 1.64 2022-11-19
|
Version 1.64 2022-11-19
|
||||||
* shared_func.[hc]: normalize_path use type string_t for general purpose
|
* shared_func.[hc]: normalize_path use type string_t for general purpose
|
||||||
|
|
|
||||||
|
|
@ -2393,7 +2393,7 @@ int parse_bytes(const char *pStr, const int default_unit_bytes, int64_t *bytes)
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
pReservedEnd = NULL;
|
pReservedEnd = NULL;
|
||||||
*bytes = strtol(pStr, &pReservedEnd, 10);
|
*bytes = strtoll(pStr, &pReservedEnd, 10);
|
||||||
if (*bytes < 0)
|
if (*bytes < 0)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, " \
|
||||||
|
|
@ -2408,6 +2408,19 @@ int parse_bytes(const char *pStr, const int default_unit_bytes, int64_t *bytes)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (*pReservedEnd == ' ' || *pReservedEnd == '\t')
|
||||||
|
{
|
||||||
|
do {
|
||||||
|
++pReservedEnd;
|
||||||
|
} while (*pReservedEnd == ' ' || *pReservedEnd == '\t');
|
||||||
|
|
||||||
|
if (*pReservedEnd == '\0')
|
||||||
|
{
|
||||||
|
*bytes *= default_unit_bytes;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (*pReservedEnd == 'T' || *pReservedEnd == 't')
|
if (*pReservedEnd == 'T' || *pReservedEnd == 't')
|
||||||
{
|
{
|
||||||
*bytes *= 1024 * 1024 * 1024 * 1024LL;
|
*bytes *= 1024 * 1024 * 1024 * 1024LL;
|
||||||
|
|
@ -2439,16 +2452,34 @@ int parse_bytes(const char *pStr, const int default_unit_bytes, int64_t *bytes)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if ((*(pReservedEnd + 1) == 'B' || *(pReservedEnd + 1) == 'b') &&
|
|
||||||
(*(pReservedEnd + 2) == '\0'))
|
++pReservedEnd;
|
||||||
|
if (*pReservedEnd == 'B' || *pReservedEnd == 'b')
|
||||||
{
|
{
|
||||||
return 0;
|
if (*(pReservedEnd + 1) == '\0')
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
++pReservedEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (*pReservedEnd == ' ' || *pReservedEnd == '\t')
|
||||||
|
{
|
||||||
|
do {
|
||||||
|
++pReservedEnd;
|
||||||
|
} while (*pReservedEnd == ' ' || *pReservedEnd == '\t');
|
||||||
|
|
||||||
|
if (*pReservedEnd == '\0')
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
result = EINVAL;
|
result = EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"unkown byte unit: %s, input string: %s",
|
"unkown byte unit: \"%s\", input string: \"%s\"",
|
||||||
__LINE__, pReservedEnd, pStr);
|
__LINE__, pReservedEnd, pStr);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue