Document dehumanize_number(3).

This commit is contained in:
jmmv 2008-02-09 09:09:04 +00:00
parent 04ac16e077
commit 2630bb2c25
1 changed files with 41 additions and 4 deletions

View File

@ -1,6 +1,6 @@
.\" $NetBSD: humanize_number.3,v 1.6 2007/12/14 16:31:20 xtraeme Exp $
.\" $NetBSD: humanize_number.3,v 1.7 2008/02/09 09:09:04 jmmv Exp $
.\"
.\" Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
.\" Copyright (c) 1999, 2002, 2008 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
@ -34,15 +34,18 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd December 14, 2007
.Dd February 9, 2008
.Dt HUMANIZE_NUMBER 3
.Os
.Sh NAME
.Nm dehumanize_number ,
.Nm humanize_number
.Nd format a number into a human readable form
.Nd format a number into a human readable form and viceversa
.Sh SYNOPSIS
.In stdlib.h
.Ft int
.Fn dehumanize_number "const char *str" "int64_t *result"
.Ft int
.Fn humanize_number "char *buf" "size_t len" "int64_t number" "const char *suffix" "int scale" "int flags"
.Sh DESCRIPTION
The
@ -120,6 +123,15 @@ Divide
.Fa number
with 1000 instead of 1024.
.El
.Pp
The
.Fn dehumanize_number
function parses the string representing an integral value given in
.Fa str
and stores the numerical value in the integer pointed to by
.Fa result .
The provided string may hold one of the suffixes, which will be interpreted
and used to scale up its accompanying numerical value.
.Sh RETURN VALUES
.Fn humanize_number
returns the number of characters stored in
@ -128,9 +140,34 @@ returns the number of characters stored in
If
.Dv HN_GETSCALE
is specified, the prefix index number will be returned instead.
.Pp
.Fn dehumanize_number
returns 0 if the string was parsed correctly.
A \-1 is returned to indicate failure and an error code is stored in
.Va errno .
.Sh ERRORS
.Fn dehumanize_number
will fail and no number will be stored in
.Fa result
if:
.Bl -tag -width Er
.It Bq Er EINVAL
The string in
.Fa str
was empty or carried an unknown suffix.
.It Bq Er ERANGE
The string in
.Fa str
represented a number that does not fit in
.Fa result .
.El
.Sh SEE ALSO
.Xr humanize_number 9
.Sh HISTORY
.Fn humanize_number
first appeared in
.Nx 2.0 .
.Pp
.Fn dehumanize_number
first appeared in
.Nx 5.0 .