xref: /netbsd-src/lib/libc/stdlib/strsuftoll.3 (revision 5c1bce6b004543139b4353c192c43b41fb1e0a5b)
1*5c1bce6bSjruoho.\"	$NetBSD: strsuftoll.3,v 1.11 2010/12/14 13:00:34 jruoho Exp $
26ca5b5bbSlukem.\"
32d50a590Slukem.\" Copyright (c) 2002,2007 The NetBSD Foundation, Inc.
46ca5b5bbSlukem.\" All rights reserved.
56ca5b5bbSlukem.\"
66ca5b5bbSlukem.\" This code is derived from software contributed to The NetBSD Foundation
76ca5b5bbSlukem.\" by Luke Mewburn.
86ca5b5bbSlukem.\"
96ca5b5bbSlukem.\" Redistribution and use in source and binary forms, with or without
106ca5b5bbSlukem.\" modification, are permitted provided that the following conditions
116ca5b5bbSlukem.\" are met:
126ca5b5bbSlukem.\" 1. Redistributions of source code must retain the above copyright
136ca5b5bbSlukem.\"    notice, this list of conditions and the following disclaimer.
146ca5b5bbSlukem.\" 2. Redistributions in binary form must reproduce the above copyright
156ca5b5bbSlukem.\"    notice, this list of conditions and the following disclaimer in the
166ca5b5bbSlukem.\"    documentation and/or other materials provided with the distribution.
176ca5b5bbSlukem.\"
186ca5b5bbSlukem.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
196ca5b5bbSlukem.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
206ca5b5bbSlukem.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
216ca5b5bbSlukem.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
226ca5b5bbSlukem.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
236ca5b5bbSlukem.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
246ca5b5bbSlukem.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
256ca5b5bbSlukem.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
266ca5b5bbSlukem.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
276ca5b5bbSlukem.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
286ca5b5bbSlukem.\" POSSIBILITY OF SUCH DAMAGE.
296ca5b5bbSlukem.\"
30*5c1bce6bSjruoho.Dd December 14, 2010
316ca5b5bbSlukem.Dt STRSUFTOLL 3
326ca5b5bbSlukem.Os
336ca5b5bbSlukem.Sh NAME
346ca5b5bbSlukem.Nm strsuftoll ,
356ca5b5bbSlukem.Nm strsuftollx
36454f40b7Swiz.Nd "convert a string to a long long, with suffix parsing"
376ca5b5bbSlukem.Sh LIBRARY
386ca5b5bbSlukem.Lb libc
396ca5b5bbSlukem.Sh SYNOPSIS
40472351e1Swiz.In stdlib.h
416ca5b5bbSlukem.Ft long long
426ca5b5bbSlukem.Fn strsuftoll "const char *desc" "const char *val" "long long min" "long long max"
436ca5b5bbSlukem.Ft long long
446ca5b5bbSlukem.Fn strsuftollx "const char *desc" "const char *val" "long long min" "long long max" "char *errbuf" "size_t errbuflen"
456ca5b5bbSlukem.Sh DESCRIPTION
466ca5b5bbSlukemThe functions
476ca5b5bbSlukem.Fn strsuftoll
486ca5b5bbSlukemand
496ca5b5bbSlukem.Fn strsuftollx
506ca5b5bbSlukemconvert
516ca5b5bbSlukem.Fa val
52413ef23aSjruohointo a number of type
53413ef23aSjruoho.Vt long long ,
546ca5b5bbSlukemchecking that the result is not smaller than
556ca5b5bbSlukem.Fa min
566ca5b5bbSlukemor larger than
576ca5b5bbSlukem.Fa max .
58a19008b1SlukemTwo or more decimal numbers may be separated by an
596ca5b5bbSlukem.Dq x
606ca5b5bbSlukemto indicate a product.
61413ef23aSjruoho.Pp
62a19008b1SlukemEach decimal number may have one of the following optional suffixes:
63413ef23aSjruoho.Pp
646ca5b5bbSlukem.Bl -tag -width 3n -offset indent -compact
65413ef23aSjruoho.It Em b
666ca5b5bbSlukemBlock; multiply by 512
67413ef23aSjruoho.It Em k
682d50a590SlukemKibi; multiply by 1024 (1 KiB)
69413ef23aSjruoho.It Em m
702d50a590SlukemMebi; multiply by 1048576 (1 MiB)
71413ef23aSjruoho.It Em g
722d50a590SlukemGibi; multiply by 1073741824 (1 GiB)
73413ef23aSjruoho.It Em t
742d50a590SlukemTebi; multiply by 1099511627776 (1 TiB)
75413ef23aSjruoho.It Em w
766ca5b5bbSlukemWord; multiply by the number of bytes in an integer
776ca5b5bbSlukem.El
786ca5b5bbSlukem.Pp
796ca5b5bbSlukemIn the case of an error (range overflow or an invalid number),
806ca5b5bbSlukem.Fn strsuftollx
81454f40b7Swizplaces an error message into
826ca5b5bbSlukem.Fa errbuf
836ca5b5bbSlukem(which is
846ca5b5bbSlukem.Fa errbuflen
856ca5b5bbSlukembytes long) and returns 0,
866ca5b5bbSlukemand
876ca5b5bbSlukem.Fn strsuftoll
886ca5b5bbSlukemdisplays that error and terminates the process.
89413ef23aSjruohoThe parameter
90413ef23aSjruoho.Fa desc
91413ef23aSjruohois used to construct
92413ef23aSjruoho.Fa errbuf .
93413ef23aSjruoho.Pp
94413ef23aSjruohoNeither
95413ef23aSjruoho.Fa desc
96413ef23aSjruohonor
97413ef23aSjruoho.Fa val
98413ef23aSjruohomay be
99413ef23aSjruoho.Dv NULL .
1006ca5b5bbSlukem.Sh RETURN VALUES
1016ca5b5bbSlukemThe functions
1026ca5b5bbSlukem.Fn strsuftoll
1036ca5b5bbSlukemand
1046ca5b5bbSlukem.Fn strsuftollx
1056ca5b5bbSlukemreturn either the result of the conversion,
1066ca5b5bbSlukemunless the value overflows or is not a number;
1076ca5b5bbSlukemin the latter case,
1086ca5b5bbSlukem.Fn strsuftoll
10906135114Sjruohodisplays an error message and terminates the process with exit code
11006135114Sjruoho.Dv EXIT_FAILURE ,
1116ca5b5bbSlukemand
1126ca5b5bbSlukem.Fn strsuftollx
1136ca5b5bbSlukemreturns with 0 and
1146ca5b5bbSlukem.Fa errbuf
1156ca5b5bbSlukemcontains a non-empty error message.
1166ca5b5bbSlukem.Sh ERRORS
1176ca5b5bbSlukem.Bl -tag -width Er
1186ca5b5bbSlukem.It Bq Er ERANGE
1196ca5b5bbSlukemThe given string was out of range; the value converted has been clamped.
1206ca5b5bbSlukem.El
1216ca5b5bbSlukem.Sh SEE ALSO
1226ca5b5bbSlukem.Xr errx 3 ,
123*5c1bce6bSjruoho.Xr strtoll 3 ,
124*5c1bce6bSjruoho.Xr orders 7
1256ca5b5bbSlukem.Sh BUGS
126413ef23aSjruohoAt least few limitations should be mentioned:
127413ef23aSjruoho.Bl -bullet
128413ef23aSjruoho.It
129413ef23aSjruohoBoth functions ignore the current locale.
130413ef23aSjruoho.It
131413ef23aSjruohoNeither
132413ef23aSjruoho.Fn strsuftoll
133413ef23aSjruohonor
134413ef23aSjruoho.Fn strsuftollx
135413ef23aSjruohofail gracefully in case of invalid,
136413ef23aSjruoho.Dv NULL ,
137413ef23aSjruohopointers.
138413ef23aSjruoho.It
139280488d6SjruohoArguably the return type should be
140280488d6Sjruoho.Vt intmax_t
141280488d6Sjruohoinstead of
142280488d6Sjruoho.Vt long long .
143280488d6Sjruoho.It
144413ef23aSjruohoThe
145413ef23aSjruoho.Fn strsuftollx
146413ef23aSjruohofunction is prone to buffer overflows if used incorrectly.
147413ef23aSjruohoArguably only
148413ef23aSjruoho.Fn strsuftoll
149413ef23aSjruohoshould be exposed to a caller.
150413ef23aSjruoho.El
151