poll.2: Remove <signal.h>
[man-pages.git] / man3 / atoi.3
blob19a5487775445204c2dd008ec5abf390e687be8d
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" References consulted:
26 .\"     Linux libc source code
27 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
28 .\"     386BSD man pages
29 .\" Modified Mon Mar 29 22:39:41 1993, David Metcalfe
30 .\" Modified Sat Jul 24 21:38:42 1993, Rik Faith (faith@cs.unc.edu)
31 .\" Modified Sun Dec 17 18:35:06 2000, Joseph S. Myers
32 .\"
33 .TH ATOI 3  2021-03-22 "GNU" "Linux Programmer's Manual"
34 .SH NAME
35 atoi, atol, atoll \- convert a string to an integer
36 .SH SYNOPSIS
37 .nf
38 .B #include <stdlib.h>
39 .PP
40 .BI "int atoi(const char *" nptr );
41 .BI "long atol(const char *" nptr );
42 .BI "long long atoll(const char *" nptr );
43 .fi
44 .PP
45 .RS -4
46 Feature Test Macro Requirements for glibc (see
47 .BR feature_test_macros (7)):
48 .RE
49 .PP
50 .BR atoll ():
51 .nf
52     _ISOC99_SOURCE
53         || /* Glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
54 .fi
55 .SH DESCRIPTION
56 The
57 .BR atoi ()
58 function converts the initial portion of the string
59 pointed to by \fInptr\fP to
60 .IR int .
61 The behavior is the same as
62 .PP
63 .in +4n
64 .EX
65 strtol(nptr, NULL, 10);
66 .EE
67 .in
68 .PP
69 except that
70 .BR atoi ()
71 does not detect errors.
72 .PP
73 The
74 .BR atol ()
75 and
76 .BR atoll ()
77 functions behave the same as
78 .BR atoi (),
79 except that they convert the initial portion of the
80 string to their return type of \fIlong\fP or \fIlong long\fP.
81 .SH RETURN VALUE
82 The converted value or 0 on error.
83 .SH ATTRIBUTES
84 For an explanation of the terms used in this section, see
85 .BR attributes (7).
86 .ad l
87 .nh
88 .TS
89 allbox;
90 lbx lb lb
91 l l l.
92 Interface       Attribute       Value
94 .BR atoi (),
95 .BR atol (),
96 .BR atoll ()
97 T}      Thread safety   MT-Safe locale
98 .TE
99 .hy
101 .sp 1
102 .SH CONFORMING TO
103 POSIX.1-2001, POSIX.1-2008, C99, SVr4, 4.3BSD.
104 C89 and
105 POSIX.1-1996 include the functions
106 .BR atoi ()
108 .BR atol ()
109 only.
110 .\" .SH NOTES
111 .\" Linux libc provided
112 .\" .BR atoq ()
113 .\" as an obsolete name for
114 .\" .BR atoll ();
115 .\" .BR atoq ()
116 .\" is not provided by glibc.
117 .\" The
118 .\" .BR atoll ()
119 .\" function is present in glibc 2 since version 2.0.2, but
120 .\" not in libc4 or libc5.
121 .SH NOTES
122 POSIX.1 leaves the return value of
123 .BR atoi ()
124 on error unspecified.
125 On glibc, musl libc, and uClibc, 0 is returned on error.
126 .SH BUGS
127 .I errno
128 is not set on error so there is no way to distinguish between 0 as an
129 error and as the converted value.
130 No checks for overflow or underflow are done.
131 Only base-10 input can be converted.
132 It is recommended to instead use the
133 .BR strtol ()
135 .BR strtoul ()
136 family of functions in new programs.
137 .SH SEE ALSO
138 .BR atof (3),
139 .BR strtod (3),
140 .BR strtol (3),
141 .BR strtoul (3)