diff options
Diffstat (limited to 'src/lib/libc/stdlib/atoi.3')
-rw-r--r-- | src/lib/libc/stdlib/atoi.3 | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/src/lib/libc/stdlib/atoi.3 b/src/lib/libc/stdlib/atoi.3 index 219ba73c00..dee8b637a3 100644 --- a/src/lib/libc/stdlib/atoi.3 +++ b/src/lib/libc/stdlib/atoi.3 | |||
@@ -1,5 +1,5 @@ | |||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 1 | .\" Copyright (c) 1990, 1991, 1993 |
2 | .\" All rights reserved. | 2 | .\" The Regents of the University of California. All rights reserved. |
3 | .\" | 3 | .\" |
4 | .\" This code is derived from software contributed to Berkeley by | 4 | .\" This code is derived from software contributed to Berkeley by |
5 | .\" the American National Standards Committee X3, on Information | 5 | .\" the American National Standards Committee X3, on Information |
@@ -13,11 +13,7 @@ | |||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 3. Neither the name of the University nor the names of its contributors |
17 | .\" must display the following acknowledgement: | ||
18 | .\" This product includes software developed by the University of | ||
19 | .\" California, Berkeley and its contributors. | ||
20 | .\" 4. Neither the name of the University nor the names of its contributors | ||
21 | .\" may be used to endorse or promote products derived from this software | 17 | .\" may be used to endorse or promote products derived from this software |
22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
23 | .\" | 19 | .\" |
@@ -33,10 +29,9 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
35 | .\" | 31 | .\" |
36 | .\" from: @(#)atoi.3 5.3 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: atoi.3,v 1.8 2004/08/22 21:47:41 jaredy Exp $ |
37 | .\" $Id: atoi.3,v 1.1.1.1 1995/10/18 08:42:16 deraadt Exp $ | ||
38 | .\" | 33 | .\" |
39 | .Dd June 29, 1991 | 34 | .Dd June 4, 1993 |
40 | .Dt ATOI 3 | 35 | .Dt ATOI 3 |
41 | .Os | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
@@ -52,13 +47,12 @@ string to integer | |||
52 | The | 47 | The |
53 | .Fn atoi | 48 | .Fn atoi |
54 | function converts the initial portion of the string pointed to by | 49 | function converts the initial portion of the string pointed to by |
55 | .Em nptr | 50 | .Fa nptr |
56 | to | 51 | to |
57 | .Em integer | 52 | .Li integer |
58 | representation. | 53 | representation. |
59 | .Pp | 54 | .Pp |
60 | It is equivalent to: | 55 | It is equivalent to: |
61 | .Pp | ||
62 | .Bd -literal -offset indent | 56 | .Bd -literal -offset indent |
63 | (int)strtol(nptr, (char **)NULL, 10); | 57 | (int)strtol(nptr, (char **)NULL, 10); |
64 | .Ed | 58 | .Ed |
@@ -67,9 +61,26 @@ It is equivalent to: | |||
67 | .Xr atol 3 , | 61 | .Xr atol 3 , |
68 | .Xr strtod 3 , | 62 | .Xr strtod 3 , |
69 | .Xr strtol 3 , | 63 | .Xr strtol 3 , |
64 | .Xr strtonum 3 , | ||
70 | .Xr strtoul 3 | 65 | .Xr strtoul 3 |
71 | .Sh STANDARDS | 66 | .Sh STANDARDS |
72 | The | 67 | The |
73 | .Fn atoi | 68 | .Fn atoi |
74 | function conforms to | 69 | function conforms to |
75 | .St -ansiC . | 70 | .St -ansiC . |
71 | .Sh CAVEATS | ||
72 | .Nm | ||
73 | does no overflow checking, handles unsigned numbers poorly, | ||
74 | and handles strings containing trailing extra characters | ||
75 | (like | ||
76 | .Dq "123abc" ) | ||
77 | poorly. | ||
78 | Careful use of | ||
79 | .Xr strtol 3 | ||
80 | and | ||
81 | .Xr strtoul 3 | ||
82 | can alleviate these problems, | ||
83 | but | ||
84 | .Xr strtonum 3 | ||
85 | can be used to convert numbers from strings much more safely | ||
86 | and easily. | ||