1STRTOUL(3P)                POSIX Programmer's Manual               STRTOUL(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       strtoul, strtoull — convert a string to an unsigned long
14

SYNOPSIS

16       #include <stdlib.h>
17
18       unsigned long strtoul(const char *restrict str,
19           char **restrict endptr, int base);
20       unsigned long long strtoull(const char *restrict str,
21           char **restrict endptr, int base);
22

DESCRIPTION

24       The functionality described on this reference page is aligned with  the
25       ISO C  standard.  Any  conflict between the requirements described here
26       and the ISO C standard is unintentional. This  volume  of  POSIX.1‐2008
27       defers to the ISO C standard.
28
29       These functions shall convert the initial portion of the string pointed
30       to by str to a type unsigned long and unsigned  long  long  representa‐
31       tion,  respectively.  First, they decompose the input string into three
32       parts:
33
34        1. An initial, possibly empty, sequence of white-space characters  (as
35           specified by isspace())
36
37        2. A  subject  sequence  interpreted as an integer represented in some
38           radix determined by the value of base
39
40        3. A final string of one or more  unrecognized  characters,  including
41           the terminating NUL character of the input string
42
43       Then  they shall attempt to convert the subject sequence to an unsigned
44       integer, and return the result.
45
46       If the value of base is 0, the expected form of the subject sequence is
47       that  of  a  decimal constant, octal constant, or hexadecimal constant,
48       any of which may be preceded by a '+' or '−' sign. A  decimal  constant
49       begins  with  a  non-zero  digit, and consists of a sequence of decimal
50       digits. An octal constant consists of the prefix  '0'  optionally  fol‐
51       lowed  by  a sequence of the digits '0' to '7' only. A hexadecimal con‐
52       stant consists of the prefix 0x or 0X followed by  a  sequence  of  the
53       decimal  digits and letters 'a' (or 'A') to 'f' (or 'F') with values 10
54       to 15 respectively.
55
56       If the value of base is between 2 and 36, the expected form of the sub‐
57       ject sequence is a sequence of letters and digits representing an inte‐
58       ger with the radix specified by base, optionally preceded by a  '+'  or
59       '−'  sign.  The letters from 'a' (or 'A') to 'z' (or 'Z') inclusive are
60       ascribed the values 10 to 35; only letters whose  ascribed  values  are
61       less  than  that of base are permitted. If the value of base is 16, the
62       characters 0x or 0X may optionally precede the sequence of letters  and
63       digits, following the sign if present.
64
65       The  subject  sequence is defined as the longest initial subsequence of
66       the input string, starting with  the  first  non-white-space  character
67       that  is  of  the  expected form. The subject sequence shall contain no
68       characters if the input string is empty or consists entirely of  white-
69       space  characters,  or  if the first non-white-space character is other
70       than a sign or a permissible letter or digit.
71
72       If the subject sequence has the expected form and the value of base  is
73       0,  the  sequence  of characters starting with the first digit shall be
74       interpreted as an integer constant. If the  subject  sequence  has  the
75       expected  form  and  the value of base is between 2 and 36, it shall be
76       used as the base for conversion, ascribing to each letter its value  as
77       given  above.  If  the  subject  sequence begins with a minus-sign, the
78       value resulting from the conversion shall be negated. A pointer to  the
79       final  string  shall be stored in the object pointed to by endptr, pro‐
80       vided that endptr is not a null pointer.
81
82       In other than the C or POSIX locales, other implementation-defined sub‐
83       ject sequences may be accepted.
84
85       If the subject sequence is empty or does not have the expected form, no
86       conversion shall be performed; the value of str shall be stored in  the
87       object  pointed  to  by  endptr,  provided  that  endptr  is not a null
88       pointer.
89
90       These functions shall not change the setting of errno if successful.
91
92       Since 0, {ULONG_MAX}, and {ULLONG_MAX} are returned on  error  and  are
93       also  valid  returns  on  success,  an application wishing to check for
94       error situations should set errno to 0, then  call  strtoul()  or  str‐
95       toull(), then check errno.
96

RETURN VALUE

98       Upon  successful completion, these functions shall return the converted
99       value, if any. If no conversion could be performed, 0 shall be returned
100       and errno may be set to [EINVAL].
101
102       If  the  value  of base is not supported, 0 shall be returned and errno
103       shall be set to [EINVAL].
104
105       If the correct value is outside  the  range  of  representable  values,
106       {ULONG_MAX}  or  {ULLONG_MAX}  shall  be  returned  and  errno  set  to
107       [ERANGE].
108

ERRORS

110       These functions shall fail if:
111
112       EINVAL The value of base is not supported.
113
114       ERANGE The value to be returned is not representable.
115
116       These functions may fail if:
117
118       EINVAL No conversion could be performed.
119
120       The following sections are informative.
121

EXAMPLES

123       None.
124

APPLICATION USAGE

126       Since the value of *endptr is unspecified if the value of base  is  not
127       supported,  applications should either ensure that base has a supported
128       value (0 or between 2 and 36) before the call, or check for an [EINVAL]
129       error before examining *endptr.
130

RATIONALE

132       None.
133

FUTURE DIRECTIONS

135       None.
136

SEE ALSO

138       fscanf(), isalpha(), strtod(), strtol()
139
140       The Base Definitions volume of POSIX.1‐2008, <stdlib.h>
141
143       Portions  of  this text are reprinted and reproduced in electronic form
144       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
145       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
146       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
147       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
148       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
149       event of any discrepancy between this version and the original IEEE and
150       The Open Group Standard, the original IEEE and The Open Group  Standard
151       is  the  referee document. The original Standard can be obtained online
152       at http://www.unix.org/online.html .
153
154       Any typographical or formatting errors that appear  in  this  page  are
155       most likely to have been introduced during the conversion of the source
156       files to man page format. To report such errors,  see  https://www.ker
157       nel.org/doc/man-pages/reporting_bugs.html .
158
159
160
161IEEE/The Open Group                  2013                          STRTOUL(3P)
Impressum