xref: /netbsd/lib/libc/stdlib/strsuftoll.3 (revision c4a72b64)
1.\"	$NetBSD: strsuftoll.3,v 1.2 2002/11/29 19:19:39 wiz Exp $
2.\"
3.\" Copyright (c) 2002 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Luke Mewburn.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"        This product includes software developed by the NetBSD
20.\"        Foundation, Inc. and its contributors.
21.\" 4. Neither the name of The NetBSD Foundation nor the names of its
22.\"    contributors may be used to endorse or promote products derived
23.\"    from this software without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35.\" POSSIBILITY OF SUCH DAMAGE.
36.\"
37.Dd November 29, 2002
38.Dt STRSUFTOLL 3
39.Os
40.Sh NAME
41.Nm strsuftoll ,
42.Nm strsuftollx
43.Nd "convert a string to a long long, with suffix parsing"
44.Sh LIBRARY
45.Lb libc
46.Sh SYNOPSIS
47.Fd #include \*[Lt]stdlib.h\*[Gt]
48.Ft long long
49.Fn strsuftoll "const char *desc" "const char *val" "long long min" "long long max"
50.Ft long long
51.Fn strsuftollx "const char *desc" "const char *val" "long long min" "long long max" "char *errbuf" "size_t errbuflen"
52.Sh DESCRIPTION
53The functions
54.Fn strsuftoll
55and
56.Fn strsuftollx
57convert
58.Fa val
59into a long long number,
60checking that the result is not smaller than
61.Fa min
62or larger than
63.Fa max .
64Two or more numbers may be separated by an
65.Dq x
66to indicate a product.
67Each number may have one of the following optional suffices:
68.Bl -tag -width 3n -offset indent -compact
69.It b
70Block; multiply by 512
71.It k
72Kilo; multiply by 1024 (1 KB)
73.It m
74Mega; multiply by 1048576 (1 MB)
75.It g
76Giga; multiply by 1073741824 (1 GB)
77.It t
78Tera; multiply by 1099511627776 (1 TB)
79.It w
80Word; multiply by the number of bytes in an integer
81.El
82.Pp
83In the case of an error (range overflow or an invalid number),
84.Fn strsuftollx
85places an error message into
86.Fa errbuf
87(which is
88.Fa errbuflen
89bytes long) and returns 0,
90and
91.Fn strsuftoll
92displays that error and terminates the process.
93.Sh RETURN VALUES
94The functions
95.Fn strsuftoll
96and
97.Fn strsuftollx
98return either the result of the conversion,
99unless the value overflows or is not a number;
100in the latter case,
101.Fn strsuftoll
102displays an error message and terminates the process with exit code 1,
103and
104.Fn strsuftollx
105returns with 0 and
106.Fa errbuf
107contains a non-empty error message.
108.Sh ERRORS
109.Bl -tag -width Er
110.It Bq Er ERANGE
111The given string was out of range; the value converted has been clamped.
112.El
113.Sh SEE ALSO
114.Xr errx 3 ,
115.Xr strtoll 3
116.Sh BUGS
117Ignores the current locale.
118