Debian Codegraph @

upstream/debian-trixie/man3/atoi.3

raw
1 '\" t
2 .\" Copyright 1993 David Metcalfe ([email protected])
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .\" References consulted:
7 .\" Linux libc source code
8 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
9 .\" 386BSD man pages
10 .\" Modified Mon Mar 29 22:39:41 1993, David Metcalfe
11 .\" Modified Sat Jul 24 21:38:42 1993, Rik Faith ([email protected])
12 .\" Modified Sun Dec 17 18:35:06 2000, Joseph S. Myers
13 .\"
14 .TH atoi 3 2024-05-02 "Linux man-pages 6.9.1"
15 .SH NAME
16 atoi, atol, atoll \- convert a string to an integer
17 .SH LIBRARY
18 Standard C library
19 .RI ( libc ", " \-lc )
20 .SH SYNOPSIS
21 .nf
22 .B #include <stdlib.h>
23 .P
24 .BI "int atoi(const char *" nptr );
25 .BI "long atol(const char *" nptr );
26 .BI "long long atoll(const char *" nptr );
27 .fi
28 .P
29 .RS -4
30 Feature Test Macro Requirements for glibc (see
31 .BR feature_test_macros (7)):
32 .RE
33 .P
34 .BR atoll ():
35 .nf
36 _ISOC99_SOURCE
37 || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
38 .fi
39 .SH DESCRIPTION
40 The
41 .BR atoi ()
42 function converts the initial portion of the string
43 pointed to by \fInptr\fP to
44 .IR int .
45 The behavior is the same as
46 .P
47 .in +4n
48 .EX
49 strtol(nptr, NULL, 10);
50 .EE
51 .in
52 .P
53 except that
54 .BR atoi ()
55 does not detect errors.
56 .P
57 The
58 .BR atol ()
59 and
60 .BR atoll ()
61 functions behave the same as
62 .BR atoi (),
63 except that they convert the initial portion of the
64 string to their return type of \fIlong\fP or \fIlong long\fP.
65 .SH RETURN VALUE
66 The converted value or 0 on error.
67 .SH ATTRIBUTES
68 For an explanation of the terms used in this section, see
69 .BR attributes (7).
70 .TS
71 allbox;
72 lbx lb lb
73 l l l.
74 Interface Attribute Value
75 T{
76 .na
77 .nh
78 .BR atoi (),
79 .BR atol (),
80 .BR atoll ()
81 T} Thread safety MT-Safe locale
82 .TE
83 .SH VERSIONS
84 POSIX.1 leaves the return value of
85 .BR atoi ()
86 on error unspecified.
87 On glibc, musl libc, and uClibc, 0 is returned on error.
88 .SH STANDARDS
89 C11, POSIX.1-2008.
90 .SH HISTORY
91 C99, POSIX.1-2001, SVr4, 4.3BSD.
92 .P
93 C89 and
94 POSIX.1-1996 include the functions
95 .BR atoi ()
96 and
97 .BR atol ()
98 only.
99 .\" .SH NOTES
100 .\" Linux libc provided
101 .\" .BR atoq ()
102 .\" as an obsolete name for
103 .\" .BR atoll ();
104 .\" .BR atoq ()
105 .\" is not provided by glibc.
106 .\" The
107 .\" .BR atoll ()
108 .\" function is present since glibc 2.0.2, but
109 .\" not in libc4 or libc5.
110 .SH BUGS
111 .I errno
112 is not set on error so there is no way to distinguish between 0 as an
113 error and as the converted value.
114 No checks for overflow or underflow are done.
115 Only base-10 input can be converted.
116 It is recommended to instead use the
117 .BR strtol ()
118 and
119 .BR strtoul ()
120 family of functions in new programs.
121 .SH SEE ALSO
122 .BR atof (3),
123 .BR strtod (3),
124 .BR strtol (3),
125 .BR strtoul (3)