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

NAME

12       strtoul, strtoull - convert a string to an unsigned long
13

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

94       Upon  successful completion, these functions shall return the converted
95       value, if any. If no conversion could be performed, 0 shall be returned
96       and  errno may be set to [EINVAL].  If the correct value is outside the
97       range of representable values, {ULONG_MAX}  or  {ULLONG_MAX}  shall  be
98       returned and errno set to [ERANGE].
99

ERRORS

101       These functions shall fail if:
102
103       EINVAL The value of base is not supported.
104
105       ERANGE The value to be returned is not representable.
106
107
108       These functions may fail if:
109
110       EINVAL No conversion could be performed.
111
112
113       The following sections are informative.
114

EXAMPLES

116       None.
117

APPLICATION USAGE

119       None.
120

RATIONALE

122       None.
123

FUTURE DIRECTIONS

125       None.
126

SEE ALSO

128       isalpha(),  scanf(), strtod(), strtol(), the Base Definitions volume of
129       IEEE Std 1003.1-2001, <stdlib.h>
130
132       Portions of this text are reprinted and reproduced in  electronic  form
133       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
134       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
135       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
136       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
137       event of any discrepancy between this version and the original IEEE and
138       The Open Group Standard, the original IEEE and The Open Group  Standard
139       is  the  referee document. The original Standard can be obtained online
140       at http://www.opengroup.org/unix/online.html .
141
142
143
144IEEE/The Open Group                  2003                          STRTOUL(3P)
Impressum