1ATOI(3)                    Linux Programmer's Manual                   ATOI(3)
2
3
4

NAME

6       atoi, atol, atoll - convert a string to an integer
7

SYNOPSIS

9       #include <stdlib.h>
10
11       int atoi(const char *nptr);
12       long atol(const char *nptr);
13       long long atoll(const char *nptr);
14
15   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
16
17       atoll():
18           _ISOC99_SOURCE
19               || /* Glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
20

DESCRIPTION

22       The  atoi() function converts the initial portion of the string pointed
23       to by nptr to int.  The behavior is the same as
24
25           strtol(nptr, NULL, 10);
26
27       except that atoi() does not detect errors.
28
29       The atol() and atoll() functions behave the same as atoi(), except that
30       they  convert the initial portion of the string to their return type of
31       long or long long.
32

RETURN VALUE

34       The converted value or 0 on error.
35

ATTRIBUTES

37       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
38       tributes(7).
39
40       ┌─────────────────────────────────────┬───────────────┬────────────────┐
41Interface                            Attribute     Value          
42       ├─────────────────────────────────────┼───────────────┼────────────────┤
43atoi(), atol(), atoll()              │ Thread safety │ MT-Safe locale │
44       └─────────────────────────────────────┴───────────────┴────────────────┘
45

CONFORMING TO

47       POSIX.1-2001,  POSIX.1-2008,  C99,  SVr4, 4.3BSD.  C89 and POSIX.1-1996
48       include the functions atoi() and atol() only.
49

NOTES

51       POSIX.1 leaves the return value of atoi()  on  error  unspecified.   On
52       glibc, musl libc, and uClibc, 0 is returned on error.
53

BUGS

55       errno  is  not set on error so there is no way to distinguish between 0
56       as an error and as the converted value.  No checks for overflow or  un‐
57       derflow  are  done.  Only base-10 input can be converted.  It is recom‐
58       mended to instead use the strtol() and strtoul() family of functions in
59       new programs.
60

SEE ALSO

62       atof(3), strtod(3), strtol(3), strtoul(3)
63

COLOPHON

65       This  page  is  part of release 5.13 of the Linux man-pages project.  A
66       description of the project, information about reporting bugs,  and  the
67       latest     version     of     this    page,    can    be    found    at
68       https://www.kernel.org/doc/man-pages/.
69
70
71
72GNU                               2021-03-22                           ATOI(3)
Impressum