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