parse_bytes support space charactors

remotes/origin/fstore_storage_engine
YuQing 2023-01-04 12:20:04 +08:00
parent 8ab3420bce
commit fd8fbfe644
2 changed files with 38 additions and 6 deletions

View File

@ -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
* add function tcp_socket_connected
* parse_bytes support space charactors (before and after the unit)
Version 1.64 2022-11-19
* shared_func.[hc]: normalize_path use type string_t for general purpose

View File

@ -2393,7 +2393,7 @@ int parse_bytes(const char *pStr, const int default_unit_bytes, int64_t *bytes)
int result;
pReservedEnd = NULL;
*bytes = strtol(pStr, &pReservedEnd, 10);
*bytes = strtoll(pStr, &pReservedEnd, 10);
if (*bytes < 0)
{
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;
}
if (*pReservedEnd == ' ' || *pReservedEnd == '\t')
{
do {
++pReservedEnd;
} while (*pReservedEnd == ' ' || *pReservedEnd == '\t');
if (*pReservedEnd == '\0')
{
*bytes *= default_unit_bytes;
return 0;
}
}
if (*pReservedEnd == 'T' || *pReservedEnd == 't')
{
*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;
}
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;
}
logError("file: "__FILE__", line: %d, "
"unkown byte unit: %s, input string: %s",
"unkown byte unit: \"%s\", input string: \"%s\"",
__LINE__, pReservedEnd, pStr);
return result;
}