2 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\" References consulted:
7 .\" Linux libc source code
8 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
10 .\" Modified Mon Mar 29 22:39:41 1993, David Metcalfe
11 .\" Modified Sat Jul 24 21:38:42 1993, Rik Faith (faith@cs.unc.edu)
12 .\" Modified Sun Dec 17 18:35:06 2000, Joseph S. Myers
14 .TH atoi 3 (date) "Linux man-pages (unreleased)"
16 atoi, atol, atoll \- convert a string to an integer
19 .RI ( libc ", " \-lc )
22 .B #include <stdlib.h>
24 .BI "int atoi(const char *" nptr );
25 .BI "long atol(const char *" nptr );
26 .BI "long long atoll(const char *" nptr );
30 Feature Test Macro Requirements for glibc (see
31 .BR feature_test_macros (7)):
37 || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
42 function converts the initial portion of the string
43 pointed to by \fInptr\fP to
45 The behavior is the same as
49 strtol(nptr, NULL, 10);
55 does not detect errors.
61 functions behave the same as
63 except that they convert the initial portion of the
64 string to their return type of \fIlong\fP or \fIlong long\fP.
66 The converted value or 0 on error.
68 For an explanation of the terms used in this section, see
76 Interface Attribute Value
81 T} Thread safety MT-Safe locale
87 POSIX.1-2001, POSIX.1-2008, C99, SVr4, 4.3BSD.
89 .\" Linux libc provided
91 .\" as an obsolete name for
94 .\" is not provided by glibc.
97 .\" function is present since glibc 2.0.2, but
98 .\" not in libc4 or libc5.
100 POSIX.1 leaves the return value of
102 on error unspecified.
103 On glibc, musl libc, and uClibc, 0 is returned on error.
106 is not set on error so there is no way to distinguish between 0 as an
107 error and as the converted value.
108 No checks for overflow or underflow are done.
109 Only base-10 input can be converted.
110 It is recommended to instead use the
114 family of functions in new programs.