diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libzutil/zutil_nicenum.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/libzutil/zutil_nicenum.c b/lib/libzutil/zutil_nicenum.c index 9a81011fc..306cec3ca 100644 --- a/lib/libzutil/zutil_nicenum.c +++ b/lib/libzutil/zutil_nicenum.c @@ -23,11 +23,26 @@ * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. */ +#include <ctype.h> #include <math.h> #include <stdio.h> #include <libzutil.h> /* + * Return B_TRUE if "str" is a number string, B_FALSE otherwise. + * Works for integer and floating point numbers. + */ +boolean_t +zfs_isnumber(const char *str) +{ + for (; *str; str++) + if (!(isdigit(*str) || (*str == '.'))) + return (B_FALSE); + + return (B_TRUE); +} + +/* * Convert a number to an appropriately human-readable output. */ void |