9330 stack overflow when creating a deeply nested dataset
[unleashed.git] / usr / src / man / man3c / strtol.3c
blobd3b9f7123f44c63016cbca86ec8f979c4ff047a1
1 .\"
2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
6 .\"
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
9 .\" documentation.
10 .\"
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
13 .\"
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group.  In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document.  The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
24 .\"
25 .\" This notice shall appear on any product containing this material.
26 .\"
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
30 .\"
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
35 .\"
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
41 .\"
42 .\"
43 .\" Copyright 1989 AT&T.
44 .\" Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
45 .\" Portions Copyright (c) 2004, Sun Microsystems, Inc.  All Rights Reserved
46 .\"
47 .TH STRTOL 3C "May 6, 2003"
48 .SH NAME
49 strtol, strtoll, atol, atoll, atoi, lltostr, ulltostr \- string conversion
50 routines
51 .SH SYNOPSIS
52 .LP
53 .nf
54 #include <stdlib.h>
56 \fBlong\fR \fBstrtol\fR(\fBconst char *restrict\fR \fIstr\fR, \fBchar **restrict\fR \fIendptr\fR, \fBint\fR \fIbase\fR);
57 .fi
59 .LP
60 .nf
61 \fBlong long\fR \fBstrtoll\fR(\fBconst char *restrict\fR \fIstr\fR, \fBchar **restrict\fR \fIendptr\fR,
62      \fBint\fR \fIbase\fR);
63 .fi
65 .LP
66 .nf
67 \fBlong\fR \fBatol\fR(\fBconst char *\fR\fIstr\fR);
68 .fi
70 .LP
71 .nf
72 \fBlong long\fR \fBatoll\fR(\fBconst char *\fR\fIstr\fR);
73 .fi
75 .LP
76 .nf
77 \fBint\fR \fBatoi\fR(\fBconst char *\fR\fIstr\fR);
78 .fi
80 .LP
81 .nf
82 \fBchar *\fR\fBlltostr\fR(\fBlong long\fR \fIvalue\fR, \fBchar *\fR\fIendptr\fR);
83 .fi
85 .LP
86 .nf
87 \fBchar *\fR\fBulltostr\fR(\fBunsigned long long\fR \fIvalue\fR, \fBchar *\fR\fIendptr\fR);
88 .fi
90 .SH DESCRIPTION
91 .SS "\fBstrtol()\fR and \fBstrtoll()\fR"
92 .sp
93 .LP
94 The \fBstrtol()\fR function converts the initial portion of the string pointed
95 to by \fIstr\fR to a type \fBlong int\fR representation.
96 .sp
97 .LP
98 The \fBstrtoll()\fR function converts the initial portion of the string pointed
99 to by \fIstr\fR to a type \fBlong long\fR representation.
102 Both functions first decompose the input string into three parts: an initial,
103 possibly empty, sequence of white-space characters (as specified by
104 \fBisspace\fR(3C)); a subject sequence interpreted as an integer represented in
105 some radix determined by the value of \fIbase\fR; and a final string of one or
106 more unrecognized characters, including the terminating null byte of the input
107 string. They then attempt to convert the subject sequence to an integer and
108 return the result.
111 If the value of \fIbase\fR is 0, the expected form of the subject sequence is
112 that of a decimal constant, octal constant or hexadecimal constant, any of
113 which may be preceded by a + or \(mi sign. A decimal constant begins with a
114 non-zero digit, and consists of a sequence of decimal digits. An octal constant
115 consists of the prefix 0 optionally followed by a sequence of the digits 0 to 7
116 only. A hexadecimal constant consists of the prefix 0x or 0X followed by a
117 sequence of the decimal digits and letters a (or A) to f (or F) with values 10
118 to 15 respectively.
121 If the value of \fIbase\fR is between 2 and 36, the expected form of the
122 subject sequence is a sequence of letters and digits representing an integer
123 with the radix specified by \fIbase\fR, optionally preceded by a + or \(mi
124 sign. The letters from a (or A) to z (or Z) inclusive are ascribed the values
125 10 to 35; only letters whose ascribed values are less than that of \fIbase\fR
126 are permitted. If the value of \fIbase\fR is 16, the characters 0x or 0X may
127 optionally precede the sequence of letters and digits, following the sign if
128 present.
131 The subject sequence is defined as the longest initial subsequence of the input
132 string, starting with the first non-white-space character, that is of the
133 expected form. The subject sequence contains no characters if the input string
134 is empty or consists entirely of white-space characters, or if the first
135 non-white-space character is other than a sign or a permissible letter or
136 digit.
139 If the subject sequence has the expected form and the value of \fIbase\fR is 0,
140 the sequence of characters starting with the first digit is interpreted as an
141 integer constant. If the subject sequence has the expected form and the value
142 of \fIbase\fR is between 2 and 36, it is used as the base for conversion,
143 ascribing to each letter its value as given above. If the subject sequence
144 begins with a minus sign, the value resulting from the conversion is negated. A
145 pointer to the final string is stored in the object pointed to by \fIendptr\fR,
146 provided that \fIendptr\fR is not a null pointer.
149 In other than the POSIX locale, additional implementation-dependent subject
150 sequence forms may be accepted.
153 If the subject sequence is empty or does not have the expected form, no
154 conversion is performed; the value of \fIstr\fR is stored in the object pointed
155 to by \fIendptr\fR, provided that \fIendptr\fR is not a null pointer.
156 .SS "\fBatol()\fR, \fBatoll()\fR and \fBatoi()\fR"
159 Except for behavior on error, \fBatol()\fR is equivalent to: \fBstrtol(str,
160 (char **)NULL, 10)\fR.
163 Except for behavior on error, \fBatoll()\fR is equivalent to: \fBstrtoll(str,
164 (char **)NULL, 10)\fR.
167 Except for behavior on error, \fBatoi()\fR is equivalent to: \fB(int)
168 strtol(str, (char **)NULL, 10)\fR.
171 If the value cannot be represented, the behavior is undefined.
172 .SS "\fBlltostr()\fR and \fBulltostr()\fR"
175 The \fBlltostr()\fR function returns a pointer to the string represented by the
176 \fBlong\fR \fBlong\fR \fIvalue\fR. The \fIendptr\fR argument is assumed to
177 point to the byte following a storage area into which the decimal
178 representation of \fIvalue\fR is to be placed as a string.  The \fBlltostr()\fR
179 function converts \fIvalue\fR to decimal and produces the string,  and returns
180 a pointer to the beginning of the string. No leading zeros are produced, and no
181 terminating null is produced. The low-order digit of the result always occupies
182 memory position  \fIendptr\fR\(mi1. The behavior of \fBlltostr()\fR is
183 undefined if  \fIvalue\fR is negative.  A single zero digit is produced if
184 \fIvalue\fR is 0.
187 The \fBulltostr()\fR function is similar to \fBlltostr()\fR except that
188 \fIvalue\fR is an \fBunsigned long long\fR.
189 .SH RETURN VALUES
192 Upon successful completion, \fBstrtol()\fR, \fBstrtoll()\fR, \fBatol()\fR,
193 \fBatoll()\fR, and \fBatoi()\fR return the converted value, if any. If no
194 conversion could be performed, \fBstrtol()\fR and \fBstrtoll()\fR return
195 \fB0\fR and \fBerrno\fR may be set to \fBEINVAL\fR.
198 If the correct value is outside the range of representable values,
199 \fBstrtol()\fR returns \fBLONG_MAX\fR or \fBLONG_MIN\fR and \fBstrtoll()\fR
200 returns \fBLLONG_MAX\fR or \fBLLONG_MIN\fR (according to the sign of the
201 value), and \fBerrno\fR is set to \fBERANGE\fR.
204 Upon successful completion, \fBlltostr()\fR and \fBulltostr()\fR return a
205 pointer to the converted string.
206 .SH ERRORS
209 The \fBstrtol()\fR and \fBstrtoll()\fR functions will fail if:
211 .ne 2
213 \fB\fBERANGE\fR\fR
215 .RS 10n
216 The value to be returned is not representable. The \fBstrtol()\fR and
217 \fBstrtoll()\fR functions may fail if:
221 .ne 2
223 \fB\fBEINVAL\fR\fR
225 .RS 10n
226 The value of \fIbase\fR is not supported.
229 .SH USAGE
232 Because 0, \fBLONG_MIN\fR, \fBLONG_MAX\fR, \fBLLONG_MIN\fR, and \fBLLONG_MAX\fR
233 are returned on error and are also valid returns on success, an application
234 wishing to check for error situations should set \fBerrno\fR to 0, call the
235 function, then check \fBerrno\fR and if it is non-zero, assume an error has
236 occurred.
239 The \fBstrtol()\fR function no longer accepts values greater than
240 \fBLONG_MAX\fR or \fBLLONG_MAX\fR as valid input. Use \fBstrtoul\fR(3C)
241 instead.
244 Calls to \fBatoi()\fR and \fBatol()\fR might be faster than corresponding calls
245 to \fBstrtol()\fR, and calls to \fBatoll()\fR might be faster than
246 corresponding calls to \fBstrtoll()\fR. However, applications should not use
247 the \fBatoi()\fR, \fBatol()\fR, or \fBatoll()\fR functions unless they know the
248 value represented by the argument will be in range for the corresponding result
249 type.
250 .SH ATTRIBUTES
253 See \fBattributes\fR(5) for descriptions of the following attributes:
258 box;
259 c | c
260 l | l .
261 ATTRIBUTE TYPE  ATTRIBUTE VALUE
263 Interface Stability     See below.
265 MT-Level        MT-Safe
270 The \fBstrtol()\fR, \fBstrtoll()\fR, \fBatol()\fR, \fBatoll()\fR, and
271 \fBatoi()\fR functions are Standard.
272 .SH SEE ALSO
275 \fBisalpha\fR(3C), \fBisspace\fR(3C), \fBscanf\fR(3C), \fBstrtod\fR(3C),
276 \fBstrtoul\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)