1 .\" $NetBSD: strtou.3,v 1.3 2015/07/11 15:51:33 wiz Exp $
3 .\" Copyright (c) 1990, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" This code is derived from software contributed to Berkeley by
7 .\" Chris Torek and the American National Standards Committee X3,
8 .\" on Information Processing Systems.
10 .\" Redistribution and use in source and binary forms, with or without
11 .\" modification, are permitted provided that the following conditions
13 .\" 1. Redistributions of source code must retain the above copyright
14 .\" notice, this list of conditions and the following disclaimer.
15 .\" 2. Redistributions in binary form must reproduce the above copyright
16 .\" notice, this list of conditions and the following disclaimer in the
17 .\" documentation and/or other materials provided with the distribution.
18 .\" 3. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" from: @(#)strtoul.3 8.1 (Berkeley) 6/4/93
36 .\" Created by Kamil Rytarowski, based on ID:
37 .\" NetBSD: strtoul.3,v 1.29 2015/03/10 13:00:58 christos Exp
44 .Nd convert a string to an uintmax_t integer
51 .Fa "const char * restrict nptr"
52 .Fa "char ** restrict endptr"
61 function converts the string in
68 function uses internally
70 and ensures that the result is always in the range [
74 In adddition it always places
76 on success or a conversion status in the
78 argument, avoiding the
80 gymnastics the other functions require.
85 if conversion status is to be ignored.
87 The string may begin with an arbitrary amount of white space
90 followed by a single optional
98 the string may then include a
101 and the number will be read in base 16; otherwise, a zero
103 is taken as 10 (decimal) unless the next character is
105 in which case it is taken as 8 (octal).
107 The remainder of the string is converted to an
109 value in the obvious manner,
110 stopping at the end of the string
111 or at the first character that does not produce a valid digit
113 (In bases above 10, the letter
115 in either upper or lower case
118 represents 11, and so forth, with
126 stores the address of the first invalid character in
128 If there were no digits at all, however,
130 stores the original value of
142 on return, the entire string was valid.)
147 always returns the closest value in the range specified by
156 value is guaranteed to be left unchanged.
158 Errors are stored as the conversion status in the
162 The following example will always return a number in
164 range no matter what the input is, and warn if the conversion failed.
165 .Bd -literal -offset indent
167 uintmax_t lval = strtou(buf, NULL, 0, 1, 99, &e);
169 warnc(e, "conversion of `%s' to a number failed, using %ju",
175 The string did not contain any characters that were converted.
179 is not between 2 and 36 and does not contain the special value 0.
181 The string contained non-numeric characters that did not get converted.
184 points to the first unconverted character.
186 The given string was out of range; the value converted has been clamped; or
187 the range given was invalid, i.e.
214 function first appeared in
219 function for the same purpose, but the interface makes it impossible to
220 properly differentiate illegal returns.
222 Ignores the current locale.