提交 d8427002 编写于 作者: J Jes Sorensen 提交者: Kevin Wolf

Introduce strtosz_suffix()

This introduces strtosz_suffix() which allows the caller to specify a
default suffix in case the non default of MB is wanted.

strtosz() is kept as a wrapper for strtosz_suffix() which keeps it's
current default of MB.
Signed-off-by: NJes Sorensen <Jes.Sorensen@redhat.com>
Reviewed-by: NStefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
上级 df2dbb4a
......@@ -291,10 +291,10 @@ int fcntl_setfl(int fd, int flag)
* value must be terminated by whitespace, ',' or '\0'. Return -1 on
* error.
*/
ssize_t strtosz(const char *nptr, char **end)
ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
{
ssize_t retval = -1;
char *endptr, c;
char *endptr, c, d;
int mul_required = 0;
double val, mul, integral, fraction;
......@@ -313,10 +313,16 @@ ssize_t strtosz(const char *nptr, char **end)
* part of a multi token argument.
*/
c = *endptr;
d = c;
if (isspace(c) || c == '\0' || c == ',') {
c = 0;
if (default_suffix) {
d = default_suffix;
} else {
d = c;
}
}
switch (c) {
switch (d) {
case 'B':
case 'b':
mul = 1;
......@@ -371,3 +377,8 @@ fail:
return retval;
}
ssize_t strtosz(const char *nptr, char **end)
{
return strtosz_suffix(nptr, end, STRTOSZ_DEFSUFFIX_MB);
}
......@@ -149,7 +149,14 @@ time_t mktimegm(struct tm *tm);
int qemu_fls(int i);
int qemu_fdatasync(int fd);
int fcntl_setfl(int fd, int flag);
#define STRTOSZ_DEFSUFFIX_TB 'T'
#define STRTOSZ_DEFSUFFIX_GB 'G'
#define STRTOSZ_DEFSUFFIX_MB 'M'
#define STRTOSZ_DEFSUFFIX_KB 'K'
#define STRTOSZ_DEFSUFFIX_B 'B'
ssize_t strtosz(const char *nptr, char **end);
ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix);
/* path.c */
void init_paths(const char *prefix);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册