xref: /f-stack/tools/libutil/expand_number.3 (revision 22ce4aff)
11eaf0ac3Slogwang.\" Copyright (c) 2007 Eric Anderson <[email protected]>
21eaf0ac3Slogwang.\" Copyright (c) 2007 Pawel Jakub Dawidek <[email protected]>
31eaf0ac3Slogwang.\" All rights reserved.
41eaf0ac3Slogwang.\"
51eaf0ac3Slogwang.\" Redistribution and use in source and binary forms, with or without
61eaf0ac3Slogwang.\" modification, are permitted provided that the following conditions
71eaf0ac3Slogwang.\" are met:
81eaf0ac3Slogwang.\" 1. Redistributions of source code must retain the above copyright
91eaf0ac3Slogwang.\"    notice, this list of conditions and the following disclaimer.
101eaf0ac3Slogwang.\" 2. Redistributions in binary form must reproduce the above copyright
111eaf0ac3Slogwang.\"    notice, this list of conditions and the following disclaimer in the
121eaf0ac3Slogwang.\"    documentation and/or other materials provided with the distribution.
131eaf0ac3Slogwang.\"
141eaf0ac3Slogwang.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
151eaf0ac3Slogwang.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
161eaf0ac3Slogwang.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
171eaf0ac3Slogwang.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
181eaf0ac3Slogwang.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
191eaf0ac3Slogwang.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
201eaf0ac3Slogwang.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
211eaf0ac3Slogwang.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
221eaf0ac3Slogwang.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
231eaf0ac3Slogwang.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
241eaf0ac3Slogwang.\" SUCH DAMAGE.
251eaf0ac3Slogwang.\"
261eaf0ac3Slogwang.\" $FreeBSD$
271eaf0ac3Slogwang.\"
28*22ce4affSfengbojiang.Dd July 20, 2019
291eaf0ac3Slogwang.Dt EXPAND_NUMBER 3
301eaf0ac3Slogwang.Os
311eaf0ac3Slogwang.Sh NAME
321eaf0ac3Slogwang.Nm expand_number
331eaf0ac3Slogwang.Nd format a number from human readable form
341eaf0ac3Slogwang.Sh LIBRARY
351eaf0ac3Slogwang.Lb libutil
361eaf0ac3Slogwang.Sh SYNOPSIS
371eaf0ac3Slogwang.In libutil.h
381eaf0ac3Slogwang.Ft int
391eaf0ac3Slogwang.Fo expand_number
401eaf0ac3Slogwang.Fa "const char *buf" "uint64_t *num"
411eaf0ac3Slogwang.Fc
421eaf0ac3Slogwang.Sh DESCRIPTION
431eaf0ac3SlogwangThe
441eaf0ac3Slogwang.Fn expand_number
45*22ce4affSfengbojiangfunction parses the
461eaf0ac3Slogwang.Fa buf
47*22ce4affSfengbojiangstring and stores a unsigned 64-bit quantity at
48*22ce4affSfengbojiang.Fa *num .
491eaf0ac3Slogwang.Pp
501eaf0ac3SlogwangThe
511eaf0ac3Slogwang.Fn expand_number
521eaf0ac3Slogwangfunction
531eaf0ac3Slogwangis case-insensitive and
541eaf0ac3Slogwangfollows the SI power of two convention.
551eaf0ac3Slogwang.Pp
56*22ce4affSfengbojiangThe suffixes are:
57*22ce4affSfengbojiang.Bl -column "Suffix" "Description" "1000000000000000000" -offset indent
58*22ce4affSfengbojiang.It Sy "Suffix" Ta Sy "Description" Ta Sy "Multiplier"
591eaf0ac3Slogwang.It Li K Ta No kilo Ta 1024
601eaf0ac3Slogwang.It Li M Ta No mega Ta 1048576
611eaf0ac3Slogwang.It Li G Ta No giga Ta 1073741824
621eaf0ac3Slogwang.It Li T Ta No tera Ta 1099511627776
631eaf0ac3Slogwang.It Li P Ta No peta Ta 1125899906842624
641eaf0ac3Slogwang.It Li E Ta No exa  Ta 1152921504606846976
651eaf0ac3Slogwang.El
661eaf0ac3Slogwang.Sh RETURN VALUES
671eaf0ac3Slogwang.Rv -std
681eaf0ac3Slogwang.Sh ERRORS
691eaf0ac3SlogwangThe
701eaf0ac3Slogwang.Fn expand_number
711eaf0ac3Slogwangfunction will fail if:
721eaf0ac3Slogwang.Bl -tag -width Er
731eaf0ac3Slogwang.It Bq Er EINVAL
741eaf0ac3SlogwangThe given string contains no digits.
751eaf0ac3Slogwang.It Bq Er EINVAL
76*22ce4affSfengbojiangAn unrecognized suffix was given.
771eaf0ac3Slogwang.It Bq Er ERANGE
781eaf0ac3SlogwangResult doesn't fit into 64 bits.
791eaf0ac3Slogwang.El
801eaf0ac3Slogwang.Sh SEE ALSO
811eaf0ac3Slogwang.Xr humanize_number 3
821eaf0ac3Slogwang.Sh HISTORY
831eaf0ac3SlogwangThe
841eaf0ac3Slogwang.Fn expand_number
851eaf0ac3Slogwangfunction first appeared in
861eaf0ac3Slogwang.Fx 6.3 .
87