aboutsummaryrefslogtreecommitdiff
path: root/lib/libutil/expand_number.3
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libutil/expand_number.3')
-rw-r--r--lib/libutil/expand_number.358
1 files changed, 53 insertions, 5 deletions
diff --git a/lib/libutil/expand_number.3 b/lib/libutil/expand_number.3
index 1b932400de69..b1833cedf406 100644
--- a/lib/libutil/expand_number.3
+++ b/lib/libutil/expand_number.3
@@ -24,11 +24,12 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd July 25, 2025
+.Dd August 6, 2025
.Dt EXPAND_NUMBER 3
.Os
.Sh NAME
-.Nm expand_number
+.Nm expand_number ,
+.Nm expand_unsigned
.Nd parse a number from human readable form
.Sh LIBRARY
.Lb libutil
@@ -38,6 +39,10 @@
.Fo expand_number
.Fa "const char *buf" "int64_t *num"
.Fc
+.Ft int
+.Fo expand_unsigned
+.Fa "const char *buf" "uint64_t *num"
+.Fc
.Sh DESCRIPTION
The
.Fn expand_number
@@ -48,6 +53,17 @@ quantity in the location pointed to by its
.Fa *num
argument.
.Pp
+The
+.Fn expand_unsigned
+function is similar to
+.Fn expand_number ,
+but accepts only positive numbers in the range
+.Bq 0, Ns Dv UINT64_MAX .
+.Pp
+Both functions interpret the input
+.Dq -0
+as 0.
+.Pp
The input string must consist of a decimal number, optionally preceded
by a
.Sq +
@@ -81,20 +97,38 @@ is interpreted as 5, and
.Dq 5kb
is interpreted as 5,120).
However, the usage of this suffix is discouraged.
+.Pp
+For backward compatibility reasons, if the compiler supports generic
+selection, a macro is provided which automatically replaces calls to
+.Fn expand_number
+with calls to
+.Fn expand_unsigned
+if the type of the actual
+.Va num
+argument is compatible with
+.Vt uint64_t * .
.Sh RETURN VALUES
.Rv -std
.Sh ERRORS
The
.Fn expand_number
-function will fail if:
+and
+.Fn expand_unsigned
+functions will fail if:
.Bl -tag -width Er
.It Bq Er EINVAL
The given string does not contain a valid number.
.It Bq Er EINVAL
An unrecognized suffix was encountered.
.It Bq Er ERANGE
-The given string represents a number which does not fit into a
-.Vt int64_t .
+The given string represents a number which does not fit into an
+.Vt int64_t
+(for
+.Fn expand_number )
+or
+.Vt uint64_t
+(for
+.Fn expand_unsigned ) .
.El
.Sh SEE ALSO
.Xr humanize_number 3
@@ -103,3 +137,17 @@ The
.Fn expand_number
function first appeared in
.Fx 6.3 .
+The original implementation did not handle negative numbers correctly,
+and it was switched to taking a
+.Vt uint64_t *
+and accepting only positive numbers in
+.Fx 9.0 .
+The
+.Fn expand_unsigned
+function was added,
+and
+.Fn expand_number
+switched back to
+.Vt int64_t * ,
+in
+.Fx 15.0 .