1 |
148 |
jeremybenn |
\input texinfo.tex
|
2 |
|
|
@setfilename libc.info
|
3 |
|
|
@syncodeindex fn cp
|
4 |
|
|
|
5 |
|
|
@ifinfo
|
6 |
|
|
@format
|
7 |
|
|
START-INFO-DIR-ENTRY
|
8 |
|
|
* libc:: The ANSI C library.
|
9 |
|
|
END-INFO-DIR-ENTRY
|
10 |
|
|
@end format
|
11 |
|
|
@end ifinfo
|
12 |
|
|
|
13 |
|
|
@ifinfo
|
14 |
|
|
This file documents the ANSI C library.
|
15 |
|
|
|
16 |
|
|
Copyright (C) 1992, 1993, 1994-2008 Red Hat, Inc.
|
17 |
|
|
|
18 |
|
|
@file{libc} includes software developed by the
|
19 |
|
|
University of California, Berkeley and its contributors.
|
20 |
|
|
|
21 |
|
|
libc includes software developed by Martin Jackson, Graham Haley
|
22 |
|
|
and Steve Chamberlain of Tadpole Technology and released to Cygnus.
|
23 |
|
|
|
24 |
|
|
libc uses floating-point conversion software developed at AT&T, which
|
25 |
|
|
includes this copyright information:
|
26 |
|
|
|
27 |
|
|
The author of this software is David M. Gay.
|
28 |
|
|
|
29 |
|
|
Copyright (c) 1991 by AT&T.
|
30 |
|
|
|
31 |
|
|
Permission to use, copy, modify, and distribute this software for any
|
32 |
|
|
purpose without fee is hereby granted, provided that this entire notice
|
33 |
|
|
is included in all copies of any software which is or includes a copy
|
34 |
|
|
or modification of this software and in all copies of the supporting
|
35 |
|
|
documentation for such software.
|
36 |
|
|
|
37 |
|
|
THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
|
38 |
|
|
WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY
|
39 |
|
|
REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
|
40 |
|
|
OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
|
41 |
|
|
|
42 |
|
|
Permission is granted to make and distribute verbatim copies of
|
43 |
|
|
this manual provided the copyright notice and this permission notice
|
44 |
|
|
are preserved on all copies.
|
45 |
|
|
|
46 |
|
|
@ignore
|
47 |
|
|
Permission is granted to process this file through Tex and print the
|
48 |
|
|
results, provided the printed document carries copying permission
|
49 |
|
|
notice identical to this one except for the removal of this paragraph
|
50 |
|
|
(this paragraph not being relevant to the printed manual).
|
51 |
|
|
|
52 |
|
|
@end ignore
|
53 |
|
|
Permission is granted to copy and distribute modified versions of this
|
54 |
|
|
manual under the conditions for verbatim copying, subject to the terms
|
55 |
|
|
of the GNU General Public License, which includes the provision that the
|
56 |
|
|
entire resulting derived work is distributed under the terms of a
|
57 |
|
|
permission notice identical to this one.
|
58 |
|
|
|
59 |
|
|
Permission is granted to copy and distribute translations of this manual
|
60 |
|
|
into another language, under the above conditions for modified versions.
|
61 |
|
|
@end ifinfo
|
62 |
|
|
@iftex
|
63 |
|
|
@c @smallbook
|
64 |
|
|
@c @cropmarks
|
65 |
|
|
@finalout
|
66 |
|
|
@setchapternewpage odd
|
67 |
|
|
@settitle Red Hat newlib C Library, Full
|
68 |
|
|
@titlepage
|
69 |
|
|
@title The Red Hat newlib C Library
|
70 |
|
|
@subtitle Full Configuration
|
71 |
|
|
@sp 1
|
72 |
|
|
@subtitle @code{libc} 1.17.0
|
73 |
|
|
@subtitle December 2008
|
74 |
|
|
@author {Steve Chamberlain}
|
75 |
|
|
@author {Roland Pesch}
|
76 |
|
|
@author {Red Hat Support}
|
77 |
|
|
@author {Jeff Johnston}
|
78 |
|
|
@page
|
79 |
|
|
|
80 |
|
|
@tex
|
81 |
|
|
{\parskip=0pt
|
82 |
|
|
sac@@cygnus.com, pesch@@cygnus.com, jjohnstn@@redhat.com\hfill {\it The Red Hat newlib C Library}\par
|
83 |
|
|
Copyright \copyright{} 1992, 1993, 1994-2004 Red Hat Inc.
|
84 |
|
|
}
|
85 |
|
|
\global\parindent=0pt % Steve likes it this way
|
86 |
|
|
@end tex
|
87 |
|
|
|
88 |
|
|
@file{libc} includes software developed by the
|
89 |
|
|
University of California, Berkeley and its contributors.
|
90 |
|
|
|
91 |
|
|
@file{libc} includes software developed by Martin Jackson, Graham Haley
|
92 |
|
|
and Steve Chamberlain of Tadpole Technology and released to Cygnus.
|
93 |
|
|
|
94 |
|
|
@file{libc} uses floating-point conversion software developed at AT&T,
|
95 |
|
|
which includes this copyright information:
|
96 |
|
|
|
97 |
|
|
@cartouche
|
98 |
|
|
@quotation
|
99 |
|
|
The author of this software is David M. Gay.
|
100 |
|
|
|
101 |
|
|
Copyright (c) 1991 by AT&T.
|
102 |
|
|
|
103 |
|
|
Permission to use, copy, modify, and distribute this software for any
|
104 |
|
|
purpose without fee is hereby granted, provided that this entire notice
|
105 |
|
|
is included in all copies of any software which is or includes a copy
|
106 |
|
|
or modification of this software and in all copies of the supporting
|
107 |
|
|
documentation for such software.
|
108 |
|
|
|
109 |
|
|
THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
|
110 |
|
|
WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY
|
111 |
|
|
REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
|
112 |
|
|
OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
|
113 |
|
|
@end quotation
|
114 |
|
|
@end cartouche
|
115 |
|
|
|
116 |
|
|
Permission is granted to make and distribute verbatim copies of
|
117 |
|
|
this manual provided the copyright notice and this permission notice
|
118 |
|
|
are preserved on all copies.
|
119 |
|
|
|
120 |
|
|
Permission is granted to copy and distribute modified versions of this
|
121 |
|
|
manual under the conditions for verbatim copying, subject to the terms
|
122 |
|
|
of the GNU General Public License, which includes the provision that the
|
123 |
|
|
entire resulting derived work is distributed under the terms of a
|
124 |
|
|
permission notice identical to this one.
|
125 |
|
|
|
126 |
|
|
Permission is granted to copy and distribute translations of this manual
|
127 |
|
|
into another language, under the above conditions for modified versions.
|
128 |
|
|
@end titlepage
|
129 |
|
|
@end iftex
|
130 |
|
|
|
131 |
|
|
@ifnottex
|
132 |
|
|
@node Top
|
133 |
|
|
@top The Red Hat newlib C Library
|
134 |
|
|
|
135 |
|
|
@c The menu contents depend on the configuration, so we include them
|
136 |
|
|
@c as a separate file
|
137 |
|
|
|
138 |
|
|
@c switch to set SIGNALS on or off, according to whether config picks up
|
139 |
|
|
@c signal subdirectory:
|
140 |
|
|
@include sigset.texi
|
141 |
|
|
@include extra.texi
|
142 |
|
|
@include stdio64.texi
|
143 |
|
|
@include iconvset.texi
|
144 |
|
|
|
145 |
|
|
@menu
|
146 |
|
|
* Introduction::
|
147 |
|
|
* Stdlib::
|
148 |
|
|
* Ctype::
|
149 |
|
|
* Stdio::
|
150 |
|
|
@ifset STDIO64
|
151 |
|
|
* Stdio64::
|
152 |
|
|
@end ifset
|
153 |
|
|
|
154 |
|
|
* Strings::
|
155 |
|
|
* Wchar strings::
|
156 |
|
|
@ifset SIGNALS
|
157 |
|
|
* Signals::
|
158 |
|
|
@end ifset
|
159 |
|
|
|
160 |
|
|
* Timefns::
|
161 |
|
|
* Locale::
|
162 |
|
|
* Reentrancy::
|
163 |
|
|
|
164 |
|
|
* Misc::
|
165 |
|
|
* Syscalls::
|
166 |
|
|
* Arglists::
|
167 |
|
|
@ifset ICONV
|
168 |
|
|
* Iconv::
|
169 |
|
|
@end ifset
|
170 |
|
|
|
171 |
|
|
* Library Index::
|
172 |
|
|
@end menu
|
173 |
|
|
@end ifnottex
|
174 |
|
|
|
175 |
|
|
@node Introduction
|
176 |
|
|
@chapter Introduction
|
177 |
|
|
|
178 |
|
|
This reference manual describes the functions provided by the Red Hat
|
179 |
|
|
``newlib'' version of the standard ANSI C library. This document is not
|
180 |
|
|
intended as an overview or a tutorial for the C library. Each library
|
181 |
|
|
function is listed with a synopsis of its use, a brief description,
|
182 |
|
|
return values (including error handling), and portability issues.
|
183 |
|
|
|
184 |
|
|
Some of the library functions depend on support from the underlying
|
185 |
|
|
operating system and may not be available on every platform. For
|
186 |
|
|
embedded systems in particular, many of these underlying operating
|
187 |
|
|
system services may not be available or may not be fully functional.
|
188 |
|
|
The specific operating system subroutines required for a particular
|
189 |
|
|
library function are listed in the ``Portability'' section of the
|
190 |
|
|
function description. @xref{Syscalls}, for a description of the
|
191 |
|
|
relevant operating system calls.
|
192 |
|
|
|
193 |
|
|
@include targetdep.tex
|
194 |
|
|
|
195 |
|
|
@node Arglists
|
196 |
|
|
@chapter Variable Argument Lists
|
197 |
|
|
|
198 |
|
|
The @code{printf} family of functions is defined to accept a variable
|
199 |
|
|
number of arguments, rather than a fixed argument list. You can define
|
200 |
|
|
your own functions with a variable argument list, by using macro
|
201 |
|
|
definitions from either @file{stdarg.h} (for compatibility with ANSI C)
|
202 |
|
|
or from @file{varargs.h} (for compatibility with a popular convention
|
203 |
|
|
prior to ANSI C).
|
204 |
|
|
|
205 |
|
|
@menu
|
206 |
|
|
* Stdarg::
|
207 |
|
|
* Varargs::
|
208 |
|
|
@end menu
|
209 |
|
|
|
210 |
|
|
@node Stdarg
|
211 |
|
|
@section ANSI-standard macros, @file{stdarg.h}
|
212 |
|
|
|
213 |
|
|
In ANSI C, a function has a variable number of arguments when its
|
214 |
|
|
parameter list ends in an ellipsis (@code{...}). The parameter list
|
215 |
|
|
must also include at least one explicitly named argument; that argument
|
216 |
|
|
is used to initialize the variable list data structure.
|
217 |
|
|
|
218 |
|
|
ANSI C defines three macros (@code{va_start}, @code{va_arg}, and
|
219 |
|
|
@code{va_end}) to operate on variable argument lists. @file{stdarg.h}
|
220 |
|
|
also defines a special type to represent variable argument lists: this
|
221 |
|
|
type is called @code{va_list}.
|
222 |
|
|
|
223 |
|
|
@menu
|
224 |
|
|
* va_start::
|
225 |
|
|
* va_arg::
|
226 |
|
|
* va_end::
|
227 |
|
|
@end menu
|
228 |
|
|
|
229 |
|
|
@page
|
230 |
|
|
@node va_start
|
231 |
|
|
@subsection Initialize variable argument list
|
232 |
|
|
@findex va_start
|
233 |
|
|
@strong{Synopsis}
|
234 |
|
|
@example
|
235 |
|
|
#include <stdarg.h>
|
236 |
|
|
void va_start(va_list @var{ap}, @var{rightmost});
|
237 |
|
|
@end example
|
238 |
|
|
|
239 |
|
|
@strong{Description}@*
|
240 |
|
|
Use @code{va_start} to initialize the variable argument list @var{ap},
|
241 |
|
|
so that @code{va_arg} can extract values from it. @var{rightmost} is
|
242 |
|
|
the name of the last explicit argument in the parameter list (the
|
243 |
|
|
argument immediately preceding the ellipsis @samp{...} that flags
|
244 |
|
|
variable arguments in an ANSI C function header). You can only use
|
245 |
|
|
@code{va_start} in a function declared using this ellipsis notation
|
246 |
|
|
(not, for example, in one of its subfunctions).
|
247 |
|
|
|
248 |
|
|
@strong{Returns}@*
|
249 |
|
|
@code{va_start} does not return a result.
|
250 |
|
|
|
251 |
|
|
@strong{Portability}@*
|
252 |
|
|
ANSI C requires @code{va_start}.
|
253 |
|
|
|
254 |
|
|
@page
|
255 |
|
|
@node va_arg
|
256 |
|
|
@subsection Extract a value from argument list
|
257 |
|
|
@findex va_arg
|
258 |
|
|
@strong{Synopsis}
|
259 |
|
|
@example
|
260 |
|
|
#include <stdarg.h>
|
261 |
|
|
@var{type} va_arg(va_list @var{ap}, @var{type});
|
262 |
|
|
@end example
|
263 |
|
|
|
264 |
|
|
@strong{Description}@*
|
265 |
|
|
@code{va_arg} returns the next unprocessed value from a variable
|
266 |
|
|
argument list @var{ap} (which you must previously create with
|
267 |
|
|
@var{va_start}). Specify the type for the value as the second parameter
|
268 |
|
|
to the macro, @var{type}.
|
269 |
|
|
|
270 |
|
|
You may pass a @code{va_list} object @var{ap} to a subfunction, and use
|
271 |
|
|
@code{va_arg} from the subfunction rather than from the function
|
272 |
|
|
actually declared with an ellipsis in the header; however, in that case
|
273 |
|
|
you may @emph{only} use @code{va_arg} from the subfunction. ANSI C does
|
274 |
|
|
not permit extracting successive values from a single variable-argument
|
275 |
|
|
list from different levels of the calling stack.
|
276 |
|
|
|
277 |
|
|
There is no mechanism for testing whether there is actually a next
|
278 |
|
|
argument available; you might instead pass an argument count (or some
|
279 |
|
|
other data that implies an argument count) as one of the fixed arguments
|
280 |
|
|
in your function call.
|
281 |
|
|
|
282 |
|
|
@strong{Returns}@*
|
283 |
|
|
@code{va_arg} returns the next argument, an object of type @var{type}.
|
284 |
|
|
|
285 |
|
|
@strong{Portability}@*
|
286 |
|
|
ANSI C requires @code{va_arg}.
|
287 |
|
|
|
288 |
|
|
@page
|
289 |
|
|
@node va_end
|
290 |
|
|
@subsection Abandon a variable argument list
|
291 |
|
|
@findex va_end
|
292 |
|
|
@strong{Synopsis}
|
293 |
|
|
@example
|
294 |
|
|
#include <stdarg.h>
|
295 |
|
|
void va_end(va_list @var{ap});
|
296 |
|
|
@end example
|
297 |
|
|
|
298 |
|
|
@strong{Description}@*
|
299 |
|
|
Use @code{va_end} to declare that your program will not use the variable
|
300 |
|
|
argument list @var{ap} any further.
|
301 |
|
|
|
302 |
|
|
@strong{Returns}@*
|
303 |
|
|
@code{va_end} does not return a result.
|
304 |
|
|
|
305 |
|
|
@strong{Portability}@*
|
306 |
|
|
ANSI C requires @code{va_end}.
|
307 |
|
|
|
308 |
|
|
@node Varargs
|
309 |
|
|
@section Traditional macros, @file{varargs.h}
|
310 |
|
|
|
311 |
|
|
If your C compiler predates ANSI C, you may still be able to use
|
312 |
|
|
variable argument lists using the macros from the @file{varargs.h}
|
313 |
|
|
header file. These macros resemble their ANSI counterparts, but have
|
314 |
|
|
important differences in usage. In particular, since traditional C has
|
315 |
|
|
no declaration mechanism for variable argument lists, two additional
|
316 |
|
|
macros are provided simply for the purpose of defining functions with
|
317 |
|
|
variable argument lists.
|
318 |
|
|
|
319 |
|
|
As with @file{stdarg.h}, the type @code{va_list} is used to hold a data
|
320 |
|
|
structure representing a variable argument list.
|
321 |
|
|
|
322 |
|
|
@menu
|
323 |
|
|
* va_alist::
|
324 |
|
|
* va_start-trad::
|
325 |
|
|
* va_arg-trad::
|
326 |
|
|
* va_end-trad::
|
327 |
|
|
@end menu
|
328 |
|
|
|
329 |
|
|
@page
|
330 |
|
|
@node va_alist
|
331 |
|
|
@subsection Declare variable arguments
|
332 |
|
|
@findex va_alist
|
333 |
|
|
@findex va_dcl
|
334 |
|
|
@strong{Synopsis}
|
335 |
|
|
@example
|
336 |
|
|
#include <varargs.h>
|
337 |
|
|
@var{function}(va_alist)
|
338 |
|
|
va_dcl
|
339 |
|
|
@end example
|
340 |
|
|
|
341 |
|
|
@strong{Description}@*
|
342 |
|
|
To use the @file{varargs.h} version of variable argument lists, you must
|
343 |
|
|
declare your function with a call to the macro @code{va_alist} as its
|
344 |
|
|
argument list, and use @code{va_dcl} as the declaration. @emph{Do not
|
345 |
|
|
use a semicolon after @code{va_dcl}.}
|
346 |
|
|
|
347 |
|
|
@strong{Returns}@*
|
348 |
|
|
These macros cannot be used in a context where a return is syntactically
|
349 |
|
|
possible.
|
350 |
|
|
|
351 |
|
|
@strong{Portability}@*
|
352 |
|
|
@var{va_alist} and @var{va_dcl} were the most widespread method of
|
353 |
|
|
declaring variable argument lists prior to ANSI C.
|
354 |
|
|
|
355 |
|
|
@page
|
356 |
|
|
@node va_start-trad
|
357 |
|
|
@subsection Initialize variable argument list
|
358 |
|
|
@findex va_start
|
359 |
|
|
@strong{Synopsis}
|
360 |
|
|
@example
|
361 |
|
|
#include <varargs.h>
|
362 |
|
|
va_list @var{ap};
|
363 |
|
|
va_start(@var{ap});
|
364 |
|
|
@end example
|
365 |
|
|
|
366 |
|
|
@strong{Description}@*
|
367 |
|
|
With the @file{varargs.h} macros, use @code{va_start} to initialize a
|
368 |
|
|
data structure @var{ap} to permit manipulating a variable argument list.
|
369 |
|
|
@var{ap} must have the type @var{va_alist}.
|
370 |
|
|
|
371 |
|
|
@strong{Returns}@*
|
372 |
|
|
@code{va_start} does not return a result.
|
373 |
|
|
|
374 |
|
|
@strong{Portability}@*
|
375 |
|
|
@code{va_start} is also defined as a macro in ANSI C, but the
|
376 |
|
|
definitions are incompatible; the ANSI version has another parameter
|
377 |
|
|
besides @var{ap}.
|
378 |
|
|
|
379 |
|
|
@page
|
380 |
|
|
@node va_arg-trad
|
381 |
|
|
@subsection Extract a value from argument list
|
382 |
|
|
@findex va_arg
|
383 |
|
|
@strong{Synopsis}
|
384 |
|
|
@example
|
385 |
|
|
#include <varargs.h>
|
386 |
|
|
@var{type} va_arg(va_list @var{ap}, @var{type});
|
387 |
|
|
@end example
|
388 |
|
|
|
389 |
|
|
@strong{Description}@*
|
390 |
|
|
@code{va_arg} returns the next unprocessed value from a variable
|
391 |
|
|
argument list @var{ap} (which you must previously create with
|
392 |
|
|
@var{va_start}). Specify the type for the value as the second parameter
|
393 |
|
|
to the macro, @var{type}.
|
394 |
|
|
|
395 |
|
|
@strong{Returns}@*
|
396 |
|
|
@code{va_arg} returns the next argument, an object of type @var{type}.
|
397 |
|
|
|
398 |
|
|
@strong{Portability}@*
|
399 |
|
|
The @code{va_arg} defined in @file{varargs.h} has the same syntax and
|
400 |
|
|
usage as the ANSI C version from @file{stdarg.h}.
|
401 |
|
|
|
402 |
|
|
@page
|
403 |
|
|
@node va_end-trad
|
404 |
|
|
@subsection Abandon a variable argument list
|
405 |
|
|
@findex va_end
|
406 |
|
|
@strong{Synopsis}
|
407 |
|
|
@example
|
408 |
|
|
#include <varargs.h>
|
409 |
|
|
va_end(va_list @var{ap});
|
410 |
|
|
@end example
|
411 |
|
|
|
412 |
|
|
@strong{Description}@*
|
413 |
|
|
Use @code{va_end} to declare that your program will not use the variable
|
414 |
|
|
argument list @var{ap} any further.
|
415 |
|
|
|
416 |
|
|
@strong{Returns}@*
|
417 |
|
|
@code{va_end} does not return a result.
|
418 |
|
|
|
419 |
|
|
@strong{Portability}@*
|
420 |
|
|
The @code{va_end} defined in @file{varargs.h} has the same syntax and
|
421 |
|
|
usage as the ANSI C version from @file{stdarg.h}.
|
422 |
|
|
|
423 |
|
|
@node Library Index
|
424 |
|
|
@unnumbered Index
|
425 |
|
|
@printindex cp
|
426 |
|
|
|
427 |
|
|
@tex
|
428 |
|
|
% I think something like @colophon should be in texinfo. In the
|
429 |
|
|
% meantime:
|
430 |
|
|
\long\def\colophon{\hbox to0pt{}\vfill
|
431 |
|
|
\centerline{The body of this manual is set in}
|
432 |
|
|
\centerline{\fontname\tenrm,}
|
433 |
|
|
\centerline{with headings in {\bf\fontname\tenbf}}
|
434 |
|
|
\centerline{and examples in {\tt\fontname\tentt}.}
|
435 |
|
|
\centerline{{\it\fontname\tenit\/} and}
|
436 |
|
|
\centerline{{\sl\fontname\tensl\/}}
|
437 |
|
|
\centerline{are used for emphasis.}\vfill}
|
438 |
|
|
\page\colophon
|
439 |
|
|
% Blame: pesch@cygnus.com, 28mar91.
|
440 |
|
|
@end tex
|
441 |
|
|
|
442 |
|
|
@contents
|
443 |
|
|
@bye
|
444 |
|
|
|
445 |
|
|
|