diff options
| author | christos <christos@NetBSD.org> | 2015-05-01 14:17:56 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2015-05-01 14:17:56 +0000 |
| commit | 0325e57d92ed5ca0cf05190ea58ee17ddb486c9c (patch) | |
| tree | 7d39a189f5242407778a4dea1a69d3c7950a270c /lib/libc/stdlib | |
| parent | b8cebe31dec0ba821bdcde2c1052a311c3c2ce36 (diff) | |
- new test for strtoi
- namespace protection for strto{i,u}
- separate manpages for strto{i,u} from the ones for strto{u,}l
From: Kamil Rytarowski
Diffstat (limited to 'lib/libc/stdlib')
| -rw-r--r-- | lib/libc/stdlib/Makefile.inc | 8 | ||||
| -rw-r--r-- | lib/libc/stdlib/strtoi.3 | 223 | ||||
| -rw-r--r-- | lib/libc/stdlib/strtol.3 | 99 | ||||
| -rw-r--r-- | lib/libc/stdlib/strtou.3 | 222 | ||||
| -rw-r--r-- | lib/libc/stdlib/strtoul.3 | 100 |
5 files changed, 484 insertions, 168 deletions
diff --git a/lib/libc/stdlib/Makefile.inc b/lib/libc/stdlib/Makefile.inc index 97315041f40..cf027a7205e 100644 --- a/lib/libc/stdlib/Makefile.inc +++ b/lib/libc/stdlib/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.89 2015/02/17 20:29:21 joerg Exp $ +# $NetBSD: Makefile.inc,v 1.90 2015/05/01 14:17:56 christos Exp $ # from: @(#)Makefile.inc 8.3 (Berkeley) 2/4/95 # stdlib sources @@ -53,8 +53,8 @@ MAN+= a64l.3 abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 atoll.3 \ posix_memalign.3 posix_openpt.3 ptsname.3 \ qabs.3 qdiv.3 quick_exit.3 qsort.3 \ radixsort.3 rand48.3 rand.3 random.3 reallocarr.3 reallocarray.3 \ - strfmon.3 strsuftoll.3 strtod.3 strtol.3 strtoul.3 strtonum.3 \ - system.3 \ + strfmon.3 strsuftoll.3 strtod.3 strtoi.3 strtol.3 strtou.3 strtoul.3 \ + strtonum.3 system.3 \ tsearch.3 \ unlockpt.3 @@ -88,9 +88,7 @@ MLINKS+=strtod.3 strtof.3 strtod.3 strtold.3 MLINKS+=strtol.3 strtoimax.3 MLINKS+=strtol.3 strtoll.3 MLINKS+=strtol.3 strtoq.3 -MLINKS+=strtol.3 strtoi.3 MLINKS+=strtoul.3 strtoull.3 MLINKS+=strtoul.3 strtoumax.3 MLINKS+=strtoul.3 strtouq.3 -MLINKS+=strtoul.3 strtou.3 MLINKS+=tsearch.3 tfind.3 tsearch.3 twalk.3 tsearch.3 tdelete.3 diff --git a/lib/libc/stdlib/strtoi.3 b/lib/libc/stdlib/strtoi.3 new file mode 100644 index 00000000000..588ee183708 --- /dev/null +++ b/lib/libc/stdlib/strtoi.3 @@ -0,0 +1,223 @@ +.\" $NetBSD: strtoi.3,v 1.1 2015/05/01 14:17:56 christos Exp $ +.\" +.\" Copyright (c) 1990, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" Chris Torek and the American National Standards Committee X3, +.\" on Information Processing Systems. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)strtol.3 8.1 (Berkeley) 6/4/93 +.\" +.\" Created by Kamil Rytarowski, based on ID: +.\" NetBSD: strtol.3,v 1.31 2015/03/11 09:57:35 wiz Exp +.\" +.Dd April 30, 2015 +.Dt STRTOI 3 +.Os +.Sh NAME +.Nm strtoi +.Nd convert string value to an intmax_t integer +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In inttypes.h +.Ft intmax_t +.Fo strtoi +.Fa "const char * restrict nptr" +.Fa "char ** restrict endptr" +.Fa "int base" +.Fa "intmax_t lo" +.Fa "intmax_t hi" +.Fa "int *rstatus" +.Sh DESCRIPTION +The +.Fn strtoi +function +converts the string in +.Fa nptr +to an +.Ft intmax_t +value. +The +.Fn strtoi +function uses internally +.Xr strtoimax 3 +and ensures that the result is always in the range [ +.Fa lo .. +.Fa hi +]. +In adddition it always places +.Dv 0 +on success or a conversion status in the +.Fa rstatus +argument, avoiding the +.Dv errno +gymnastics the other functions require. +The +.Fa rstatus +argument can be +.Dv NULL +if conversion status is to be ignored. +.Pp +The string may begin with an arbitrary amount of white space +(as determined by +.Xr isspace 3 ) +followed by a single optional +.Ql + +or +.Ql - +sign. +If +.Fa base +is zero or 16, +the string may then include a +.Ql 0x +prefix, +and the number will be read in base 16; otherwise, a zero +.Fa base +is taken as 10 (decimal) unless the next character is +.Ql 0 , +in which case it is taken as 8 (octal). +.Pp +The remainder of the string is converted to a +.Em intmax_t +value in the obvious manner, +stopping at the first character which is not a valid digit +in the given base. +(In bases above 10, the letter +.Ql A +in either upper or lower case +represents 10, +.Ql B +represents 11, and so forth, with +.Ql Z +representing 35.) +.Pp +If +.Fa endptr +is non-nil, +.Fn strtoi +stores the address of the first invalid character in +.Fa *endptr . +If there were no digits at all, however, +.Fn strtoi +stores the original value of +.Fa nptr +in +.Fa *endptr . +(Thus, if +.Fa *nptr +is not +.Ql \e0 +but +.Fa **endptr +is +.Ql \e0 +on return, the entire string was valid.) +.Sh RETURN VALUES +The +.Fn strtoi +function +always returns the closest value in the range specified by +the +.Fa lo +and +.Fa hi +arguments. +.Pp +The +.Va errno +value is guaranteed to be left unchanged. +.Pp +Errors are stored as the conversion status in the +.Fa rstatus +argument. +.Sh EXAMPLES +The following example will always return a number in +.Dv [1..99] +range no matter what the input is, and warn if the conversion failed. +.Pp +.Bd -literal -offset indent +int e; +intmax_t lval = strtoi(buf, NULL, 0, 1, 99, &e); +if (e) + warnc(e, "conversion of `%s' to a number failed, using %jd", + buf, lval); +.Ed +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EINVAL +The +.Ar base +is not between 2 and 36 and does not contain the special value 0. +.It Bq Er ERANGE +The given string was out of range; the value converted has been clamped. +.It Bq Er ECANCELED +The string did not contain any characters that were converted. +.It Bq Er ENOTSUP +The string contained non-numeric characters that did not get converted. +In this case, +.Fa endptr +points to the first unconverted character. +.It Bq Er ERANGE +The range given was invalid, i.e. +.Fa lo +\*[Gt] +.Fa hi . +.El +.Sh SEE ALSO +.Xr atof 3 , +.Xr atoi 3 , +.Xr atol 3 , +.Xr atoll 3 , +.Xr strtod 3 , +.Xr strtol 3 , +.Xr strtoll 3 , +.Xr strtoimax 3 , +.Xr strtou 3 , +.Xr strtoul 3 , +.Xr strtoull 3 , +.Xr strtoumax 3 +.Sh STANDARDS +The +.Fn strtoi +function is a +.Nx +extension. +.Sh HISTORY +The +.Fn strtoi +function first appeared in +.Nx 7 . +.Ox +introduced the +.Fn strtonum 3 +function for the same purpose, but the interface makes it impossible to +properly differentiate illegal returns. +.Sh BUGS +Ignores the current locale. diff --git a/lib/libc/stdlib/strtol.3 b/lib/libc/stdlib/strtol.3 index f518a5bb70b..bf1b94543b6 100644 --- a/lib/libc/stdlib/strtol.3 +++ b/lib/libc/stdlib/strtol.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: strtol.3,v 1.31 2015/03/11 09:57:35 wiz Exp $ +.\" $NetBSD: strtol.3,v 1.32 2015/05/01 14:17:56 christos Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -33,11 +33,10 @@ .\" .\" from: @(#)strtol.3 8.1 (Berkeley) 6/4/93 .\" -.Dd March 10, 2015 +.Dd April 30, 2015 .Dt STRTOL 3 .Os .Sh NAME -.Nm strtoi , .Nm strtol , .Nm strtoll , .Nm strtoimax , @@ -55,8 +54,6 @@ .Pp .In inttypes.h .Ft intmax_t -.Fn strtoi "const char * restrict nptr" "char ** restrict endptr" "int base" "intmax_t lo" "intmax_t hi" "int *rstatus" -.Ft intmax_t .Fn strtoimax "const char * restrict nptr" "char ** restrict endptr" "int base" .Pp .In sys/types.h @@ -90,30 +87,6 @@ to an .Ft intmax_t value. The -.Fn strtoi -function -uses internally -.Fn strtoimax -and ensures that the result is always in the range [ -.Fa lo .. -.Fa hi -]. -In adddition it always places -.Dv 0 -on success or a conversion status in the -.Fa rstatus -argument, avoiding the -.Dv errno -gymnastics the other functions require. -The -.Fn strtoi -function doesn't affect errno on exit. -The -.Fa rstatus -argument can be -.Dv NULL -if conversion status is to be ignored. -The .Fn strtoq function converts the string in @@ -121,6 +94,7 @@ converts the string in to a .Ft quad_t value. +.Pp The conversion is done according to the given .Fa base , which must be between 2 and 36 inclusive, @@ -146,11 +120,9 @@ is taken as 10 (decimal) unless the next character is .Ql 0 , in which case it is taken as 8 (octal). .Pp -The remainder of the string is converted to a -.Em long -value in the obvious manner, -stopping at the first character which is not a valid digit -in the given base. +The remainder of the string is converted to an appropriate value +in the obvious manner, +stopping at the first character which is not a valid digit in the given base. (In bases above 10, the letter .Ql A in either upper or lower case @@ -162,13 +134,10 @@ representing 35.) .Pp If .Fa endptr -is non-nil, -.Fn strtol -stores the address of the first invalid character in +is non-nil, the functions store the address of the first invalid character in .Fa *endptr . If there were no digits at all, however, -.Fn strtol -stores the original value of +the functions store the original value of .Fa nptr in .Fa *endptr . @@ -183,15 +152,6 @@ is on return, the entire string was valid.) .Sh RETURN VALUES The -.Fn strtoi -function -always returns the closest value in the range specified by -the -.Fa lo -and -.Fa hi -arguments. -The .Fn strtol function returns the result of the conversion, @@ -236,21 +196,6 @@ is left unchanged. This behavior (which is unlike most library functions) is guaranteed by the pertinent standards. .Sh EXAMPLES -The -.Fn strtoi -function is the simplest to use: -.Bd -literal -offset indent -int e; -intmax_t lval = strtoi(buf, NULL, 0, 1, 99, &e); -if (e) - warnc(e, "conversion of `%s' to a number failed, using %jd", - buf, lval); -.Ed -.Pp -This will always return a number in -.Dv [1..99] -range no matter what the input is, and warn if the conversion failed. -.Pp Because the return value of .Fn strtol cannot be used unambiguously to detect an error, @@ -320,24 +265,6 @@ is not between 2 and 36 and does not contain the special value 0. .It Bq Er ERANGE The given string was out of range; the value converted has been clamped. .El -.Pp -In addition to the above errors -.Fn strtoi -returns: -.Bl -tag -width Er -.It Bq Er ECANCELED -The string did not contain any characters that were converted. -.It Bq Er ENOTSUP -The string contained non-numeric characters that did not get converted. -In this case, -.Fa endptr -points to the first unconverted character. -.It Bq Er ERANGE -The range given was invalid, i.e. -.Fa lo -\*[Gt] -.Fa hi . -.El .Sh SEE ALSO .Xr atof 3 , .Xr atoi 3 , @@ -360,9 +287,13 @@ and .Fn strtoimax functions conform to .St -isoC-99 . +.Pp The -.Fn strtoi -function appeared in -.Nx 8 . +.Fn strtoq +function is a +.Bx +legacy function equivalent to +.Fn strtoll +and should not be used in a new code. .Sh BUGS Ignores the current locale. diff --git a/lib/libc/stdlib/strtou.3 b/lib/libc/stdlib/strtou.3 new file mode 100644 index 00000000000..586a268d1d4 --- /dev/null +++ b/lib/libc/stdlib/strtou.3 @@ -0,0 +1,222 @@ +.\" $NetBSD: strtou.3,v 1.1 2015/05/01 14:17:56 christos Exp $ +.\" +.\" Copyright (c) 1990, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" Chris Torek and the American National Standards Committee X3, +.\" on Information Processing Systems. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)strtoul.3 8.1 (Berkeley) 6/4/93 +.\" +.\" Created by Kamil Rytarowski, based on ID: +.\" NetBSD: strtoul.3,v 1.29 2015/03/10 13:00:58 christos Exp +.\" +.Dd April 30, 2015 +.Dt STRTOU 3 +.Os +.Sh NAME +.Nm strtou +.Nd convert a string to an uintmax_t integer +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In inttypes.h +.Ft uintmax_t +.Fo strtou +.Fa "const char * restrict nptr" +.Fa "char ** restrict endptr" +.Fa "int base" +.Fa "uintmax_t lo" +.Fa "uintmax_t hi" +.Fa "int *rstatus" +.Sh DESCRIPTION +The +.Fn strtou +function converts the string in +.Fa nptr +to an +.Ft uintmax_t +value. +The +.Fn strtou +function uses internally +.Xr strtoumax 3 +and ensures that the result is always in the range [ +.Fa lo .. +.Fa hi +]. +In adddition it always places +.Dv 0 +on success or a conversion status in the +.Fa rstatus +argument, avoiding the +.Dv errno +gymnastics the other functions require. +The +.Fa rstatus +argument can be +.Dv NULL +if conversion status is to be ignored. +.Pp +The string may begin with an arbitrary amount of white space +(as determined by +.Xr isspace 3 ) +followed by a single optional +.Ql + +or +.Ql - +sign. +If +.Fa base +is zero or 16, +the string may then include a +.Ql 0x +prefix, +and the number will be read in base 16; otherwise, a zero +.Fa base +is taken as 10 (decimal) unless the next character is +.Ql 0 , +in which case it is taken as 8 (octal). +.Pp +The remainder of the string is converted to an +.Em uintmax_t +value in the obvious manner, +stopping at the end of the string +or at the first character that does not produce a valid digit +in the given base. +(In bases above 10, the letter +.Ql A +in either upper or lower case +represents 10, +.Ql B +represents 11, and so forth, with +.Ql Z +representing 35.) +.Pp +If +.Fa endptr +is non-nil, +.Fn strtou +stores the address of the first invalid character in +.Fa *endptr . +If there were no digits at all, however, +.Fn strtou +stores the original value of +.Fa nptr +in +.Fa *endptr . +(Thus, if +.Fa *nptr +is not +.Ql \e0 +but +.Fa **endptr +is +.Ql \e0 +on return, the entire string was valid.) +.Sh RETURN VALUES +The +.Fn strtou +function +always returns the closest value in the range specified by +the +.Fa lo +and +.Fa hi +arguments. +.Pp +The +.Va errno +value is guaranteed to be left unchanged. +.Pp +Errors are stored as the conversion status in the +.Fa rstatus +argument. +.Sh EXAMPLES +The following example will always return a number in +.Dv [1..99] +range no matter what the input is, and warn if the conversion failed. +.Bd -literal -offset indent +int e; +uintmax_t lval = strtou(buf, NULL, 0, 1, 99, &e); +if (e) + warnc(e, "conversion of `%s' to a number failed, using %ju", + buf, lval); +.Ed +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EINVAL +The +.Ar base +is not between 2 and 36 and does not contain the special value 0. +.It Bq Er ERANGE +The given string was out of range; the value converted has been clamped. +.It Bq Er ECANCELED +The string did not contain any characters that were converted. +.It Bq Er ENOTSUP +The string contained non-numeric characters that did not get converted. +In this case, +.Fa endptr +points to the first unconverted character. +.It Bq Er ERANGE +The range given was invalid, i.e. +.Fa lo +\*[Gt] +.Fa hi . +.El +.Sh SEE ALSO +.Xr atof 3 , +.Xr atoi 3 , +.Xr atol 3 , +.Xr atoll 3 , +.Xr strtod 3 , +.Xr strtoi 3 , +.Xr strtol 3 , +.Xr strtoll 3 , +.Xr strtoimax 3 , +.Xr strtoul 3 , +.Xr strtoull 3 , +.Xr strtoumax 3 +.Sh STANDARDS +The +.Fn strtou +function is a +.Nx +extension. +.Sh HISTORY +The +.Fn strtou +function first appeared in +.Nx 7 . +.Ox +introduced the +.Fn strtonum 3 +function for the same purpose, but the interface makes it impossible to +properly differentiate illegal returns. +.Sh BUGS +Ignores the current locale. diff --git a/lib/libc/stdlib/strtoul.3 b/lib/libc/stdlib/strtoul.3 index 5cb548878ff..91f95aa73f0 100644 --- a/lib/libc/stdlib/strtoul.3 +++ b/lib/libc/stdlib/strtoul.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: strtoul.3,v 1.29 2015/03/10 13:00:58 christos Exp $ +.\" $NetBSD: strtoul.3,v 1.30 2015/05/01 14:17:56 christos Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -33,11 +33,10 @@ .\" .\" from: @(#)strtoul.3 8.1 (Berkeley) 6/4/93 .\" -.Dd March 10, 2015 +.Dd April 30, 2015 .Dt STRTOUL 3 .Os .Sh NAME -.Nm strtou , .Nm strtoul , .Nm strtoull , .Nm strtoumax , @@ -55,8 +54,6 @@ .Pp .In inttypes.h .Ft uintmax_t -.Fn strtou "const char * restrict nptr" "char ** restrict endptr" "int base" "uintmax_t lo" "uintmax_t hi" "int *rstatus" -.Ft uintmax_t .Fn strtoumax "const char * restrict nptr" "char ** restrict endptr" "int base" .Pp .In sys/types.h @@ -89,26 +86,6 @@ converts the string in to an .Ft uintmax_t value. -.Fn strtou -function -uses internally -.Fn strtoumax -and ensures that the result is always in the range [ -.Fa lo .. -.Fa hi -]. -In adddition it always places -.Dv 0 -on success or a conversion status in the -.Fa rstatus -argument, avoiding the -.Dv errno -gymnastics the other functions require. -The -.Fa rstatus -argument can be -.Dv NULL -if conversion status is to be ignored. The .Fn strtouq function @@ -117,6 +94,7 @@ converts the string in to a .Ft u_quad_t value. +.Pp The conversion is done according to the given .Fa base , which must be between 2 and 36 inclusive, @@ -142,8 +120,7 @@ is taken as 10 (decimal) unless the next character is .Ql 0 , in which case it is taken as 8 (octal). .Pp -The remainder of the string is converted to an -.Em unsigned long +The remainder of the string is converted to an appropriate value in the obvious manner, stopping at the end of the string or at the first character that does not produce a valid digit @@ -159,13 +136,10 @@ representing 35.) .Pp If .Fa endptr -is non-nil, -.Fn strtoul -stores the address of the first invalid character in +is non-nil, the functions store the address of the first invalid character in .Fa *endptr . If there were no digits at all, however, -.Fn strtoul -stores the original value of +the functions store the original value of .Fa nptr in .Fa *endptr . @@ -180,15 +154,6 @@ is on return, the entire string was valid.) .Sh RETURN VALUES The -.Fn strtou -function -always returns the closest value in the range specified by -the -.Fa lo -and -.Fa hi -arguments. -The .Fn strtoul function returns either the result of the conversion @@ -233,21 +198,6 @@ is left unchanged. This behavior (which is unlike most library functions) is guaranteed by the pertinent standards. .Sh EXAMPLES -The -.Fn strtou -function is the simplest to use: -.Bd -literal -offset indent -int e; -uintmax_t lval = strtou(buf, NULL, 0, 1, 99, &e); -if (e) - warnc(e, "conversion of `%s' to a number failed, using %ju", - buf, lval); -.Ed -.Pp -This will always return a number in -.Dv [1..99] -range no matter what the input is, and warn if the conversion failed. -.Pp Because the return value of .Fn strtoul cannot be used unambiguously to detect an error, @@ -290,29 +240,17 @@ is not between 2 and 36 and does not contain the special value 0. .It Bq Er ERANGE The given string was out of range; the value converted has been clamped. .El -.Pp -In addition to the above errors -.Fn strtou -returns: -.Bl -tag -width Er -.It Bq Er ECANCELED -The string did not contain any characters that were converted. -.It Bq Er ENOTSUP -The string contained non-numeric characters that did not get converted. -In this case, -.Fa endptr -points to the first unconverted character. -.It Bq Er ERANGE -The range given was invalid, i.e. -.Fa lo -\*[Gt] -.Fa hi . -.El .Sh SEE ALSO +.Xr atof 3 , +.Xr atoi 3 , +.Xr atol 3 , +.Xr atoll 3 , +.Xr strtod 3 , .Xr strtoi 3 , -.Xr strtoimax 3 , .Xr strtol 3 , -.Xr strtoll 3 +.Xr strtoll 3 , +.Xr strtoimax 3 , +.Xr strtou 3 , .Sh STANDARDS The .Fn strtoul @@ -325,9 +263,13 @@ and .Fn strtoumax functions conform to .St -isoC-99 . +.Pp The -.Fn strtou -function appeared in -.Nx 8 . +.Fn strtouq +function is a +.Bx +legacy function equivalent to +.Fn strtoull +and should not be used in a new code. .Sh BUGS Ignores the current locale. |
