File: atoi.3

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