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