summaryrefslogtreecommitdiffstats
path: root/upstream/opensuse-tumbleweed/man3/atoi.3
blob: d1d32f52a7d244330e04d8c491f02eb6383baa05 (plain)
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
123
124
125
126
'\" t
.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
.\"
.\" SPDX-License-Identifier: Linux-man-pages-copyleft
.\"
.\" References consulted:
.\"     Linux libc source code
.\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
.\"     386BSD man pages
.\" Modified Mon Mar 29 22:39:41 1993, David Metcalfe
.\" Modified Sat Jul 24 21:38:42 1993, Rik Faith (faith@cs.unc.edu)
.\" Modified Sun Dec 17 18:35:06 2000, Joseph S. Myers
.\"
.TH atoi 3 2023-07-20 "Linux man-pages 6.05.01"
.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>
.PP
.BI "int atoi(const char *" nptr );
.BI "long atol(const char *" nptr );
.BI "long long atoll(const char *" nptr );
.fi
.PP
.RS -4
Feature Test Macro Requirements for glibc (see
.BR feature_test_macros (7)):
.RE
.PP
.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 \fInptr\fP to
.IR int .
The behavior is the same as
.PP
.in +4n
.EX
strtol(nptr, NULL, 10);
.EE
.in
.PP
except that
.BR atoi ()
does not detect errors.
.PP
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 \fIlong\fP or \fIlong long\fP.
.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
.sp 1
.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.
.PP
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)