]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - libiberty/functions.texi
./
[thirdparty/binutils-gdb.git] / libiberty / functions.texi
CommitLineData
39423523
DD
1@c Automatically generated from *.c and others (the comments before
2@c each entry tell you which file and where in that file). DO NOT EDIT!
3@c Edit the *.c files, configure with --enable-maintainer-mode,
4@c and let gather-docs build you a new copy.
5
b109e79a 6@c safe-ctype.c:25
70ecf948
DD
7@defvr Extension HOST_CHARSET
8This macro indicates the basic character set and encoding used by the
9host: more precisely, the encoding used for character constants in
10preprocessor @samp{#if} statements (the C "execution character set").
11It is defined by @file{safe-ctype.h}, and will be an integer constant
12with one of the following values:
13
14@ftable @code
15@item HOST_CHARSET_UNKNOWN
16The host character set is unknown - that is, not one of the next two
17possibilities.
18
19@item HOST_CHARSET_ASCII
20The host character set is ASCII.
21
22@item HOST_CHARSET_EBCDIC
23The host character set is some variant of EBCDIC. (Only one of the
24nineteen EBCDIC varying characters is tested; exercise caution.)
25@end ftable
26@end defvr
27
b109e79a
ILT
28@c pexecute.txh:1
29@deftypefn Extension struct pex_obj *pex_init (int @var{flags}, const char *@var{pname}, const char *@var{tempbase})
30
31Prepare to execute one or more programs, with standard output of each
32program fed to standard input of the next. This is a system
33independent interface to execute a pipeline.
34
35@var{flags} is a bitwise combination of the following:
36
37@table @code
38
39@vindex PEX_RECORD_TIMES
40@item PEX_RECORD_TIMES
41Record subprocess times if possible.
42
43@vindex PEX_USE_PIPES
44@item PEX_USE_PIPES
45Use pipes for communication between processes, if possible.
46
47@vindex PEX_SAVE_TEMPS
48@item PEX_SAVE_TEMPS
49Don't delete temporary files used for communication between
50processes.
51
52@end table
53
54@var{pname} is the name of program to be executed, used in error
55messages. @var{tempbase} is a base name to use for any required
56temporary files; it may be @code{NULL} to use a randomly chosen name.
57
58@end deftypefn
59
60@c pexecute.txh:161
61@deftypefn Extension const char *pex_one (int @var{flags}, const char *@var{executable}, char * const *@var{argv}, const char *@var{pname}, const char *@var{outname}, const char *@var{errname}, int *@var{status}, int *@var{err})
62
63An interface to @code{pex_init} to permit the easy execution of a
64single program. The return value and most of the parameters are as
65for a call to @code{pex_run}. @var{flags} is restricted to a
66combination of @code{PEX_SEARCH}, @code{PEX_STDERR_TO_STDOUT}, and
67@code{PEX_BINARY_OUTPUT}. @var{outname} is interpreted as if
68@code{PEX_LAST} were set. On a successful return, *@var{status} will
69be set to the exit status of the program.
70
71@end deftypefn
72
73@c pexecute.txh:32
74@deftypefn Extension const char *pex_run (struct pex_obj *@var{obj}, int @var{flags}, const char *@var{executable}, char * const *@var{argv}, const char *@var{outname}, const char *@var{errname}, int *@var{err})
75
76Execute one program in a pipeline. On success this returns
77@code{NULL}. On failure it returns an error message, a statically
78allocated string.
79
80@var{obj} is returned by a previous call to @code{pex_init}.
81
82@var{flags} is a bitwise combination of the following:
83
84@table @code
85
86@vindex PEX_LAST
87@item PEX_LAST
88This must be set on the last program in the pipeline. In particular,
89it should be set when executing a single program. The standard output
90of the program will be sent to @var{outname}, or, if @var{outname} is
91@code{NULL}, to the standard output of the calling program. This
92should not be set if you want to call @code{pex_read_output}
93(described below). After a call to @code{pex_run} with this bit set,
94@var{pex_run} may no longer be called with the same @var{obj}.
95
96@vindex PEX_SEARCH
97@item PEX_SEARCH
98Search for the program using the user's executable search path.
99
100@vindex PEX_SUFFIX
101@item PEX_SUFFIX
102@var{outname} is a suffix. See the description of @var{outname},
103below.
104
105@vindex PEX_STDERR_TO_STDOUT
106@item PEX_STDERR_TO_STDOUT
107Send the program's standard error to standard output, if possible.
108
109@vindex PEX_BINARY_INPUT
110@vindex PEX_BINARY_OUTPUT
111@item PEX_BINARY_INPUT
112@itemx PEX_BINARY_OUTPUT
113The standard input (output) of the program should be read (written) in
114binary mode rather than text mode. These flags are ignored on systems
115which do not distinguish binary mode and text mode, such as Unix. For
116proper behavior these flags should match appropriately--a call to
117@code{pex_run} using @code{PEX_BINARY_OUTPUT} should be followed by a
118call using @code{PEX_BINARY_INPUT}.
119@end table
120
121@var{executable} is the program to execute. @var{argv} is the set of
122arguments to pass to the program; normally @code{@var{argv}[0]} will
123be a copy of @var{executable}.
124
125@var{outname} is used to set the name of the file to use for standard
126output. There are two cases in which no output file will be used: 1)
127if @code{PEX_LAST} is not set in @var{flags}, and @code{PEX_USE_PIPES}
128was set in the call to @code{pex_init}, and the system supports pipes;
1292) if @code{PEX_LAST} is set in @var{flags}, and @var{outname} is
130@code{NULL}. Otherwise the code will use a file to hold standard
131output. If @code{PEX_LAST} is not set, this file is considered to be
132a temporary file, and it will be removed when no longer needed, unless
133@code{PEX_SAVE_TEMPS} was set in the call to @code{pex_init}.
134
135There are two cases to consider when setting the name of the file to
136hold standard output.
137
138First case: @code{PEX_SUFFIX} is set in @var{flags}. In this case
139@var{outname} may not be @code{NULL}. If the @var{tempbase} parameter
140to @code{pex_init} was not @code{NULL}, then the output file name is
141the concatenation of @var{tempbase} and @var{outname}. If
142@var{tempbase} was @code{NULL}, then the output file name is a random
143file name ending in @var{outname}.
144
145Second case: @code{PEX_SUFFIX} was not set in @var{flags}. In this
146case, if @var{outname} is not @code{NULL}, it is used as the output
147file name. If @var{outname} is @code{NULL}, and @var{tempbase} was
148not NULL, the output file name is randomly chosen using
149@var{tempbase}. Otherwise the output file name is chosen completely
150at random.
151
152@var{errname} is the file name to use for standard error output. If
153it is @code{NULL}, standard error is the same as the caller.
154Otherwise, standard error is written to the named file.
155
156On an error return, the code sets @code{*@var{err}} to an @code{errno}
157value, or to 0 if there is no relevant @code{errno}.
158
159@end deftypefn
160
39423523 161@c alloca.c:26
99b58139 162@deftypefn Replacement void* alloca (size_t @var{size})
39423523
DD
163
164This function allocates memory which will be automatically reclaimed
165after the procedure exits. The @libib{} implementation does not free
166the memory immediately but will do so eventually during subsequent
167calls to this function. Memory is allocated using @code{xmalloc} under
168normal circumstances.
169
170The header file @file{alloca-conf.h} can be used in conjunction with the
171GNU Autoconf test @code{AC_FUNC_ALLOCA} to test for and properly make
172available this function. The @code{AC_FUNC_ALLOCA} test requires that
173client code use a block of preprocessor code to be safe (see the Autoconf
174manual for more); this header incorporates that logic and more, including
99b58139 175the possibility of a GCC built-in function.
39423523
DD
176
177@end deftypefn
178
c631edf1 179@c asprintf.c:32
5d852400 180@deftypefn Extension int asprintf (char **@var{resptr}, const char *@var{format}, ...)
ba19b94f
DD
181
182Like @code{sprintf}, but instead of passing a pointer to a buffer, you
183pass a pointer to a pointer. This function will compute the size of
184the buffer needed, allocate memory with @code{malloc}, and store a
185pointer to the allocated memory in @code{*@var{resptr}}. The value
186returned is the same as @code{sprintf} would return. If memory could
5a4e47bd 187not be allocated, minus one is returned and @code{NULL} is stored in
ba19b94f
DD
188@code{*@var{resptr}}.
189
190@end deftypefn
191
39423523
DD
192@c atexit.c:6
193@deftypefn Supplemental int atexit (void (*@var{f})())
194
195Causes function @var{f} to be called at exit. Returns 0.
196
197@end deftypefn
198
199@c basename.c:6
200@deftypefn Supplemental char* basename (const char *@var{name})
201
202Returns a pointer to the last component of pathname @var{name}.
203Behavior is undefined if the pathname ends in a directory separator.
204
205@end deftypefn
206
207@c bcmp.c:6
208@deftypefn Supplemental int bcmp (char *@var{x}, char *@var{y}, int @var{count})
209
210Compares the first @var{count} bytes of two areas of memory. Returns
56056af5
DD
211zero if they are the same, nonzero otherwise. Returns zero if
212@var{count} is zero. A nonzero result only indicates a difference,
39423523
DD
213it does not indicate any sorting order (say, by having a positive
214result mean @var{x} sorts before @var{y}).
215
216@end deftypefn
217
218@c bcopy.c:3
219@deftypefn Supplemental void bcopy (char *@var{in}, char *@var{out}, int @var{length})
220
221Copies @var{length} bytes from memory region @var{in} to region
222@var{out}. The use of @code{bcopy} is deprecated in new programs.
223
224@end deftypefn
225
226@c bsearch.c:33
227@deftypefn Supplemental void* bsearch (const void *@var{key}, const void *@var{base}, size_t @var{nmemb}, size_t @var{size}, int (*@var{compar})(const void *, const void *))
228
229Performs a search over an array of @var{nmemb} elements pointed to by
230@var{base} for a member that matches the object pointed to by @var{key}.
231The size of each member is specified by @var{size}. The array contents
232should be sorted in ascending order according to the @var{compar}
233comparison function. This routine should take two arguments pointing to
234the @var{key} and to an array member, in that order, and should return an
235integer less than, equal to, or greater than zero if the @var{key} object
fa9f0e33 236is respectively less than, matching, or greater than the array member.
39423523
DD
237
238@end deftypefn
239
c631edf1 240@c argv.c:124
ba19b94f
DD
241@deftypefn Extension char** buildargv (char *@var{sp})
242
243Given a pointer to a string, parse the string extracting fields
244separated by whitespace and optionally enclosed within either single
245or double quotes (which are stripped off), and build a vector of
246pointers to copies of the string for each field. The input string
247remains unchanged. The last element of the vector is followed by a
248@code{NULL} element.
249
250All of the memory for the pointer array and copies of the string
251is obtained from @code{malloc}. All of the memory can be returned to the
252system with the single function call @code{freeargv}, which takes the
253returned result of @code{buildargv}, as it's argument.
254
5d852400 255Returns a pointer to the argument vector if successful. Returns
ba19b94f
DD
256@code{NULL} if @var{sp} is @code{NULL} or if there is insufficient
257memory to complete building the argument vector.
258
259If the input is a null string (as opposed to a @code{NULL} pointer),
260then buildarg returns an argument vector that has one arg, a null
261string.
262
263@end deftypefn
264
39423523
DD
265@c bzero.c:6
266@deftypefn Supplemental void bzero (char *@var{mem}, int @var{count})
267
fa9f0e33 268Zeros @var{count} bytes starting at @var{mem}. Use of this function
39423523
DD
269is deprecated in favor of @code{memset}.
270
271@end deftypefn
272
273@c calloc.c:6
274@deftypefn Supplemental void* calloc (size_t @var{nelem}, size_t @var{elsize})
275
276Uses @code{malloc} to allocate storage for @var{nelem} objects of
277@var{elsize} bytes each, then zeros the memory.
278
279@end deftypefn
280
ba19b94f 281@c choose-temp.c:42
5d852400 282@deftypefn Extension char* choose_temp_base (void)
ba19b94f
DD
283
284Return a prefix for temporary file names or @code{NULL} if unable to
285find one. The current directory is chosen if all else fails so the
286program is exited if a temporary directory can't be found (@code{mktemp}
287fails). The buffer for the result is obtained with @code{xmalloc}.
288
289This function is provided for backwards compatability only. Its use is
290not recommended.
291
292@end deftypefn
293
b109e79a 294@c make-temp-file.c:87
ba19b94f
DD
295@deftypefn Replacement char* choose_tmpdir ()
296
297Returns a pointer to a directory path suitable for creating temporary
298files in.
299
300@end deftypefn
301
39423523 302@c clock.c:27
99b58139 303@deftypefn Supplemental long clock (void)
39423523
DD
304
305Returns an approximation of the CPU time used by the process as a
306@code{clock_t}; divide this number by @samp{CLOCKS_PER_SEC} to get the
307number of seconds used.
308
309@end deftypefn
310
ba19b94f 311@c concat.c:24
5d852400 312@deftypefn Extension char* concat (const char *@var{s1}, const char *@var{s2}, @dots{}, @code{NULL})
ba19b94f
DD
313
314Concatenate zero or more of strings and return the result in freshly
5d852400 315@code{xmalloc}ed memory. Returns @code{NULL} if insufficient memory is
ba19b94f
DD
316available. The argument list is terminated by the first @code{NULL}
317pointer encountered. Pointers to empty strings are ignored.
318
319@end deftypefn
320
c631edf1 321@c argv.c:52
ba19b94f
DD
322@deftypefn Extension char** dupargv (char **@var{vector})
323
324Duplicate an argument vector. Simply scans through @var{vector},
325duplicating each argument until the terminating @code{NULL} is found.
5d852400 326Returns a pointer to the argument vector if successful. Returns
ba19b94f
DD
327@code{NULL} if there is insufficient memory to complete building the
328argument vector.
329
330@end deftypefn
331
b5c3b3de 332@c strerror.c:567
ba19b94f 333@deftypefn Extension int errno_max (void)
39423523
DD
334
335Returns the maximum @code{errno} value for which a corresponding
336symbolic name or message is available. Note that in the case where we
337use the @code{sys_errlist} supplied by the system, it is possible for
338there to be more symbolic names than messages, or vice versa. In
339fact, the manual page for @code{perror(3C)} explicitly warns that one
340should check the size of the table (@code{sys_nerr}) before indexing
341it, since new error codes may be added to the system before they are
342added to the table. Thus @code{sys_nerr} might be smaller than value
99b58139 343implied by the largest @code{errno} value defined in @code{<errno.h>}.
39423523
DD
344
345We return the maximum value that can be used to obtain a meaningful
346symbolic name or message.
347
348@end deftypefn
349
ba19b94f
DD
350@c fdmatch.c:23
351@deftypefn Extension int fdmatch (int @var{fd1}, int @var{fd2})
352
353Check to see if two open file descriptors refer to the same file.
354This is useful, for example, when we have an open file descriptor for
355an unnamed file, and the name of a file that we believe to correspond
356to that fd. This can happen when we are exec'd with an already open
357file (@code{stdout} for example) or from the SVR4 @file{/proc} calls
358that return open file descriptors for mapped address spaces. All we
359have to do is open the file by name and check the two file descriptors
360for a match, which is done by comparing major and minor device numbers
361and inode numbers.
362
363@end deftypefn
364
c631edf1 365@c fopen_unlocked.c:48
ac119ae8
DD
366@deftypefn Extension FILE * fdopen_unlocked (int @var{fildes}, const char * @var{mode})
367
368Opens and returns a @code{FILE} pointer via @code{fdopen}. If the
369operating system supports it, ensure that the stream is setup to avoid
370any multi-threaded locking. Otherwise return the @code{FILE} pointer
371unchanged.
372
373@end deftypefn
374
ba19b94f
DD
375@c ffs.c:3
376@deftypefn Supplemental int ffs (int @var{valu})
377
5d852400 378Find the first (least significant) bit set in @var{valu}. Bits are
ba19b94f
DD
379numbered from right to left, starting with bit 1 (corresponding to the
380value 1). If @var{valu} is zero, zero is returned.
381
382@end deftypefn
383
384@c fnmatch.txh:1
385@deftypefn Replacement int fnmatch (const char *@var{pattern}, const char *@var{string}, int @var{flags})
386
387Matches @var{string} against @var{pattern}, returning zero if it
388matches, @code{FNM_NOMATCH} if not. @var{pattern} may contain the
389wildcards @code{?} to match any one character, @code{*} to match any
390zero or more characters, or a set of alternate characters in square
391brackets, like @samp{[a-gt8]}, which match one character (@code{a}
392through @code{g}, or @code{t}, or @code{8}, in this example) if that one
5d852400 393character is in the set. A set may be inverted (i.e., match anything
ba19b94f
DD
394except what's in the set) by giving @code{^} or @code{!} as the first
395character in the set. To include those characters in the set, list them
396as anything other than the first character of the set. To include a
397dash in the set, list it last in the set. A backslash character makes
398the following character not special, so for example you could match
399against a literal asterisk with @samp{\*}. To match a literal
400backslash, use @samp{\\}.
401
402@code{flags} controls various aspects of the matching process, and is a
403boolean OR of zero or more of the following values (defined in
5d852400 404@code{<fnmatch.h>}):
ba19b94f
DD
405
406@table @code
407
408@item FNM_PATHNAME
409@itemx FNM_FILE_NAME
410@var{string} is assumed to be a path name. No wildcard will ever match
411@code{/}.
412
413@item FNM_NOESCAPE
414Do not interpret backslashes as quoting the following special character.
415
416@item FNM_PERIOD
417A leading period (at the beginning of @var{string}, or if
418@code{FNM_PATHNAME} after a slash) is not matched by @code{*} or
419@code{?} but must be matched explicitly.
420
421@item FNM_LEADING_DIR
422Means that @var{string} also matches @var{pattern} if some initial part
423of @var{string} matches, and is followed by @code{/} and zero or more
424characters. For example, @samp{foo*} would match either @samp{foobar}
425or @samp{foobar/grill}.
426
427@item FNM_CASEFOLD
428Ignores case when performing the comparison.
429
430@end table
431
432@end deftypefn
433
c631edf1 434@c fopen_unlocked.c:39
ac119ae8
DD
435@deftypefn Extension FILE * fopen_unlocked (const char *@var{path}, const char * @var{mode})
436
437Opens and returns a @code{FILE} pointer via @code{fopen}. If the
438operating system supports it, ensure that the stream is setup to avoid
439any multi-threaded locking. Otherwise return the @code{FILE} pointer
440unchanged.
441
442@end deftypefn
443
c631edf1 444@c argv.c:97
ba19b94f
DD
445@deftypefn Extension void freeargv (char **@var{vector})
446
447Free an argument vector that was built using @code{buildargv}. Simply
448scans through @var{vector}, freeing the memory for each argument until
449the terminating @code{NULL} is found, and then frees @var{vector}
450itself.
451
452@end deftypefn
453
c631edf1 454@c fopen_unlocked.c:57
ac119ae8
DD
455@deftypefn Extension FILE * freopen_unlocked (const char * @var{path}, const char * @var{mode}, FILE * @var{stream})
456
457Opens and returns a @code{FILE} pointer via @code{freopen}. If the
458operating system supports it, ensure that the stream is setup to avoid
459any multi-threaded locking. Otherwise return the @code{FILE} pointer
460unchanged.
461
462@end deftypefn
463
2a80c0a4 464@c getruntime.c:82
5d852400 465@deftypefn Replacement long get_run_time (void)
ba19b94f
DD
466
467Returns the time used so far, in microseconds. If possible, this is
468the time used by this process, else it is the elapsed time since the
469process started.
470
471@end deftypefn
472
39423523 473@c getcwd.c:6
99b58139 474@deftypefn Supplemental char* getcwd (char *@var{pathname}, int @var{len})
39423523
DD
475
476Copy the absolute pathname for the current working directory into
477@var{pathname}, which is assumed to point to a buffer of at least
478@var{len} bytes, and return a pointer to the buffer. If the current
479directory's path doesn't fit in @var{len} characters, the result is
99b58139 480@code{NULL} and @code{errno} is set. If @var{pathname} is a null pointer,
39423523
DD
481@code{getcwd} will obtain @var{len} bytes of space using
482@code{malloc}.
483
484@end deftypefn
485
486@c getpagesize.c:5
99b58139 487@deftypefn Supplemental int getpagesize (void)
39423523
DD
488
489Returns the number of bytes in a page of memory. This is the
490granularity of many of the system memory management routines. No
491guarantee is made as to whether or not it is the same as the basic
492memory management hardware page size.
493
494@end deftypefn
495
496@c getpwd.c:5
99b58139 497@deftypefn Supplemental char* getpwd (void)
39423523
DD
498
499Returns the current working directory. This implementation caches the
500result on the assumption that the process will not call @code{chdir}
501between calls to @code{getpwd}.
502
503@end deftypefn
504
0fad4bdb 505@c gettimeofday.c:12
0e867e79 506@deftypefn Supplemental int gettimeofday (struct timeval *@var{tp}, void *@var{tz})
0fad4bdb
DD
507
508Writes the current time to @var{tp}. This implementation requires
509that @var{tz} be NULL. Returns 0 on success, -1 on failure.
510
511@end deftypefn
512
c631edf1 513@c hex.c:33
7dd4d42a
DD
514@deftypefn Extension void hex_init (void)
515
516Initializes the array mapping the current character set to
517corresponding hex values. This function must be called before any
2a80c0a4
DD
518call to @code{hex_p} or @code{hex_value}. If you fail to call it, a
519default ASCII-based table will normally be used on ASCII systems.
7dd4d42a
DD
520
521@end deftypefn
522
c631edf1 523@c hex.c:42
7dd4d42a
DD
524@deftypefn Extension int hex_p (int @var{c})
525
526Evaluates to non-zero if the given character is a valid hex character,
527or zero if it is not. Note that the value you pass will be cast to
528@code{unsigned char} within the macro.
529
530@end deftypefn
531
c631edf1 532@c hex.c:50
b5c3b3de 533@deftypefn Extension {unsigned int} hex_value (int @var{c})
7dd4d42a
DD
534
535Returns the numeric equivalent of the given character when interpreted
536as a hexidecimal digit. The result is undefined if you pass an
537invalid hex digit. Note that the value you pass will be cast to
538@code{unsigned char} within the macro.
539
e4f79046
JB
540The @code{hex_value} macro returns @code{unsigned int}, rather than
541signed @code{int}, to make it easier to use in parsing addresses from
542hex dump files: a signed @code{int} would be sign-extended when
543converted to a wider unsigned type --- like @code{bfd_vma}, on some
544systems.
545
7dd4d42a
DD
546@end deftypefn
547
39423523
DD
548@c index.c:5
549@deftypefn Supplemental char* index (char *@var{s}, int @var{c})
550
fa9f0e33 551Returns a pointer to the first occurrence of the character @var{c} in
99b58139 552the string @var{s}, or @code{NULL} if not found. The use of @code{index} is
39423523
DD
553deprecated in new programs in favor of @code{strchr}.
554
555@end deftypefn
556
ba19b94f
DD
557@c insque.c:6
558@deftypefn Supplemental void insque (struct qelem *@var{elem}, struct qelem *@var{pred})
559@deftypefnx Supplemental void remque (struct qelem *@var{elem})
560
561Routines to manipulate queues built from doubly linked lists. The
562@code{insque} routine inserts @var{elem} in the queue immediately
563after @var{pred}. The @code{remque} routine removes @var{elem} from
564its containing queue. These routines expect to be passed pointers to
565structures which have as their first members a forward pointer and a
566back pointer, like this prototype (although no prototype is provided):
567
568@example
569struct qelem @{
570 struct qelem *q_forw;
571 struct qelem *q_back;
572 char q_data[];
573@};
574@end example
575
576@end deftypefn
577
b109e79a 578@c safe-ctype.c:46
70ecf948
DD
579@deffn Extension ISALPHA (@var{c})
580@deffnx Extension ISALNUM (@var{c})
581@deffnx Extension ISBLANK (@var{c})
582@deffnx Extension ISCNTRL (@var{c})
583@deffnx Extension ISDIGIT (@var{c})
584@deffnx Extension ISGRAPH (@var{c})
585@deffnx Extension ISLOWER (@var{c})
586@deffnx Extension ISPRINT (@var{c})
587@deffnx Extension ISPUNCT (@var{c})
588@deffnx Extension ISSPACE (@var{c})
589@deffnx Extension ISUPPER (@var{c})
590@deffnx Extension ISXDIGIT (@var{c})
591
592These twelve macros are defined by @file{safe-ctype.h}. Each has the
593same meaning as the corresponding macro (with name in lowercase)
594defined by the standard header @file{ctype.h}. For example,
595@code{ISALPHA} returns true for alphabetic characters and false for
596others. However, there are two differences between these macros and
597those provided by @file{ctype.h}:
598
599@itemize @bullet
600@item These macros are guaranteed to have well-defined behavior for all
601values representable by @code{signed char} and @code{unsigned char}, and
602for @code{EOF}.
603
604@item These macros ignore the current locale; they are true for these
605fixed sets of characters:
606@multitable {@code{XDIGIT}} {yada yada yada yada yada yada yada yada}
607@item @code{ALPHA} @tab @kbd{A-Za-z}
608@item @code{ALNUM} @tab @kbd{A-Za-z0-9}
609@item @code{BLANK} @tab @kbd{space tab}
610@item @code{CNTRL} @tab @code{!PRINT}
611@item @code{DIGIT} @tab @kbd{0-9}
612@item @code{GRAPH} @tab @code{ALNUM || PUNCT}
613@item @code{LOWER} @tab @kbd{a-z}
614@item @code{PRINT} @tab @code{GRAPH ||} @kbd{space}
615@item @code{PUNCT} @tab @kbd{`~!@@#$%^&*()_-=+[@{]@}\|;:'",<.>/?}
616@item @code{SPACE} @tab @kbd{space tab \n \r \f \v}
617@item @code{UPPER} @tab @kbd{A-Z}
618@item @code{XDIGIT} @tab @kbd{0-9A-Fa-f}
619@end multitable
620
621Note that, if the host character set is ASCII or a superset thereof,
622all these macros will return false for all values of @code{char} outside
623the range of 7-bit ASCII. In particular, both ISPRINT and ISCNTRL return
624false for characters with numeric values from 128 to 255.
625@end itemize
626@end deffn
627
b109e79a 628@c safe-ctype.c:95
70ecf948
DD
629@deffn Extension ISIDNUM (@var{c})
630@deffnx Extension ISIDST (@var{c})
631@deffnx Extension IS_VSPACE (@var{c})
632@deffnx Extension IS_NVSPACE (@var{c})
633@deffnx Extension IS_SPACE_OR_NUL (@var{c})
634@deffnx Extension IS_ISOBASIC (@var{c})
635These six macros are defined by @file{safe-ctype.h} and provide
636additional character classes which are useful when doing lexical
637analysis of C or similar languages. They are true for the following
638sets of characters:
639
640@multitable {@code{SPACE_OR_NUL}} {yada yada yada yada yada yada yada yada}
641@item @code{IDNUM} @tab @kbd{A-Za-z0-9_}
642@item @code{IDST} @tab @kbd{A-Za-z_}
643@item @code{VSPACE} @tab @kbd{\r \n}
644@item @code{NVSPACE} @tab @kbd{space tab \f \v \0}
645@item @code{SPACE_OR_NUL} @tab @code{VSPACE || NVSPACE}
646@item @code{ISOBASIC} @tab @code{VSPACE || NVSPACE || PRINT}
647@end multitable
648@end deffn
649
ba19b94f
DD
650@c lbasename.c:23
651@deftypefn Replacement {const char*} lbasename (const char *@var{name})
652
653Given a pointer to a string containing a typical pathname
654(@samp{/usr/src/cmd/ls/ls.c} for example), returns a pointer to the
655last component of the pathname (@samp{ls.c} in this case). The
656returned pointer is guaranteed to lie within the original
657string. This latter fact is not true of many vendor C
658libraries, which return special strings or modify the passed
659strings for particular input.
660
661In particular, the empty string returns the same empty string,
662and a path ending in @code{/} returns the empty string after it.
663
664@end deftypefn
665
ba61a412
DJ
666@c lrealpath.c:25
667@deftypefn Replacement {const char*} lrealpath (const char *@var{name})
668
669Given a pointer to a string containing a pathname, returns a canonical
670version of the filename. Symlinks will be resolved, and ``.'' and ``..''
671components will be simplified. The returned value will be allocated using
10b57b38 672@code{malloc}, or @code{NULL} will be returned on a memory allocation error.
2a80c0a4 673
ba61a412 674@end deftypefn
2a80c0a4 675
ba61a412
DJ
676@c make-relative-prefix.c:24
677@deftypefn Extension {const char*} make_relative_prefix (const char *@var{progname}, const char *@var{bin_prefix}, const char *@var{prefix})
2a80c0a4 678
ba61a412
DJ
679Given three paths @var{progname}, @var{bin_prefix}, @var{prefix},
680return the path that is in the same position relative to
681@var{progname}'s directory as @var{prefix} is relative to
682@var{bin_prefix}. That is, a string starting with the directory
683portion of @var{progname}, followed by a relative pathname of the
684difference between @var{bin_prefix} and @var{prefix}.
685
686If @var{progname} does not contain any directory separators,
687@code{make_relative_prefix} will search @env{PATH} to find a program
688named @var{progname}. Also, if @var{progname} is a symbolic link,
689the symbolic link will be resolved.
690
691For example, if @var{bin_prefix} is @code{/alpha/beta/gamma/gcc/delta},
692@var{prefix} is @code{/alpha/beta/gamma/omega/}, and @var{progname} is
693@code{/red/green/blue/gcc}, then this function will return
694@code{/red/green/blue/../../omega/}.
695
696The return value is normally allocated via @code{malloc}. If no
697relative prefix can be found, return @code{NULL}.
2a80c0a4
DD
698
699@end deftypefn
700
b109e79a 701@c make-temp-file.c:137
ba19b94f
DD
702@deftypefn Replacement char* make_temp_file (const char *@var{suffix})
703
704Return a temporary file name (as a string) or @code{NULL} if unable to
705create one. @var{suffix} is a suffix to append to the file name. The
5d852400 706string is @code{malloc}ed, and the temporary file has been created.
ba19b94f
DD
707
708@end deftypefn
709
39423523
DD
710@c memchr.c:3
711@deftypefn Supplemental void* memchr (const void *@var{s}, int @var{c}, size_t @var{n})
712
99b58139 713This function searches memory starting at @code{*@var{s}} for the
39423523
DD
714character @var{c}. The search only ends with the first occurrence of
715@var{c}, or after @var{length} characters; in particular, a null
716character does not terminate the search. If the character @var{c} is
99b58139
DD
717found within @var{length} characters of @code{*@var{s}}, a pointer
718to the character is returned. If @var{c} is not found, then @code{NULL} is
39423523
DD
719returned.
720
721@end deftypefn
722
723@c memcmp.c:6
724@deftypefn Supplemental int memcmp (const void *@var{x}, const void *@var{y}, size_t @var{count})
725
726Compares the first @var{count} bytes of two areas of memory. Returns
727zero if they are the same, a value less than zero if @var{x} is
728lexically less than @var{y}, or a value greater than zero if @var{x}
729is lexically greater than @var{y}. Note that lexical order is determined
730as if comparing unsigned char arrays.
731
732@end deftypefn
733
734@c memcpy.c:6
735@deftypefn Supplemental void* memcpy (void *@var{out}, const void *@var{in}, size_t @var{length})
736
737Copies @var{length} bytes from memory region @var{in} to region
738@var{out}. Returns a pointer to @var{out}.
739
740@end deftypefn
741
742@c memmove.c:6
743@deftypefn Supplemental void* memmove (void *@var{from}, const void *@var{to}, size_t @var{count})
744
745Copies @var{count} bytes from memory area @var{from} to memory area
746@var{to}, returning a pointer to @var{to}.
747
748@end deftypefn
749
10b57b38
DD
750@c mempcpy.c:23
751@deftypefn Supplemental void* mempcpy (void *@var{out}, const void *@var{in}, size_t @var{length})
752
753Copies @var{length} bytes from memory region @var{in} to region
754@var{out}. Returns a pointer to @var{out} + @var{length}.
755
756@end deftypefn
757
39423523
DD
758@c memset.c:6
759@deftypefn Supplemental void* memset (void *@var{s}, int @var{c}, size_t @var{count})
760
761Sets the first @var{count} bytes of @var{s} to the constant byte
762@var{c}, returning a pointer to @var{s}.
763
764@end deftypefn
765
ba19b94f
DD
766@c mkstemps.c:54
767@deftypefn Replacement int mkstemps (char *@var{template}, int @var{suffix_len})
768
769Generate a unique temporary file name from @var{template}.
770@var{template} has the form:
771
772@example
5d852400 773 @var{path}/ccXXXXXX@var{suffix}
ba19b94f
DD
774@end example
775
5d852400
DD
776@var{suffix_len} tells us how long @var{suffix} is (it can be zero
777length). The last six characters of @var{template} before @var{suffix}
778must be @samp{XXXXXX}; they are replaced with a string that makes the
ba19b94f
DD
779filename unique. Returns a file descriptor open on the file for
780reading and writing.
781
782@end deftypefn
783
b109e79a
ILT
784@c pexecute.txh:155
785@deftypefn Extension void pex_free (struct pex_obj @var{obj})
ba19b94f 786
b109e79a 787Clean up and free all data associated with @var{obj}.
ba19b94f 788
b109e79a 789@end deftypefn
ba19b94f 790
b109e79a
ILT
791@c pexecute.txh:131
792@deftypefn Extension int pex_get_status (struct pex_obj *@var{obj}, int @var{count}, int *@var{vector})
ba19b94f 793
b109e79a
ILT
794Returns the exit status of all programs run using @var{obj}.
795@var{count} is the number of results expected. The results will be
796placed into @var{vector}. The results are in the order of the calls
797to @code{pex_run}. Returns 0 on error, 1 on success.
ba19b94f 798
b109e79a 799@end deftypefn
ba19b94f 800
b109e79a
ILT
801@c pexecute.txh:140
802@deftypefn Extension int pex_get_times (struct pex_obj *@var{obj}, int @var{count}, struct pex_time *@var{vector})
ba19b94f 803
b109e79a
ILT
804Returns the process execution times of all programs run using
805@var{obj}. @var{count} is the number of results expected. The
806results will be placed into @var{vector}. The results are in the
807order of the calls to @code{pex_run}. Returns 0 on error, 1 on
808success.
ba19b94f 809
b109e79a
ILT
810@code{struct pex_time} has the following fields: @code{user_seconds},
811@code{user_microseconds}, @code{system_seconds},
812@code{system_microseconds}. On systems which do not support reporting
813process times, all the fields will be set to @code{0}.
ba19b94f
DD
814
815@end deftypefn
816
b109e79a
ILT
817@c pexecute.txh:119
818@deftypefn Extension FILE * pex_read_output (struct pex_obj *@var{obj}, int @var{binary})
819
820Returns a @code{FILE} pointer which may be used to read the standard
821output of the last program in the pipeline. When this is used,
822@code{PEX_LAST} should not be used in a call to @code{pex_run}. After
823this is called, @code{pex_run} may no longer be called with the same
824@var{obj}. @var{binary} should be non-zero if the file should be
825opened in binary mode. Don't call @code{fclose} on the returned file;
826it will be closed by @code{pex_free}.
827
828@end deftypefn
829
830@c pexecute.txh:173
831@deftypefn Extension int pexecute (const char *@var{program}, char * const *@var{argv}, const char *@var{this_pname}, const char *@var{temp_base}, char **@var{errmsg_fmt}, char **@var{errmsg_arg}, int flags)
832
833This is the old interface to execute one or more programs. It is
834still supported for compatibility purposes, but is no longer
835documented.
836
837@end deftypefn
838
839@c strsignal.c:539
ba19b94f
DD
840@deftypefn Supplemental void psignal (unsigned @var{signo}, char *@var{message})
841
842Print @var{message} to the standard error, followed by a colon,
843followed by the description of the signal specified by @var{signo},
844followed by a newline.
845
846@end deftypefn
847
39423523
DD
848@c putenv.c:21
849@deftypefn Supplemental int putenv (const char *@var{string})
850
851Uses @code{setenv} or @code{unsetenv} to put @var{string} into
852the environment or remove it. If @var{string} is of the form
99b58139 853@samp{name=value} the string is added; if no @samp{=} is present the
39423523
DD
854name is unset/removed.
855
856@end deftypefn
857
b109e79a 858@c pexecute.txh:181
ba19b94f
DD
859@deftypefn Extension int pwait (int @var{pid}, int *@var{status}, int @var{flags})
860
b109e79a 861Another part of the old execution interface.
ba19b94f
DD
862
863@end deftypefn
864
865@c random.c:39
5d852400 866@deftypefn Supplement {long int} random (void)
ba19b94f
DD
867@deftypefnx Supplement void srandom (unsigned int @var{seed})
868@deftypefnx Supplement void* initstate (unsigned int @var{seed}, void *@var{arg_state}, unsigned long @var{n})
869@deftypefnx Supplement void* setstate (void *@var{arg_state})
870
871Random number functions. @code{random} returns a random number in the
5d852400 872range 0 to @code{LONG_MAX}. @code{srandom} initializes the random
ba19b94f
DD
873number generator to some starting point determined by @var{seed}
874(else, the values returned by @code{random} are always the same for each
5d852400 875run of the program). @code{initstate} and @code{setstate} allow fine-grained
ba19b94f
DD
876control over the state of the random number generator.
877
878@end deftypefn
879
b109e79a 880@c concat.c:167
5d852400 881@deftypefn Extension char* reconcat (char *@var{optr}, const char *@var{s1}, @dots{}, @code{NULL})
ba19b94f
DD
882
883Same as @code{concat}, except that if @var{optr} is not @code{NULL} it
884is freed after the string is created. This is intended to be useful
885when you're extending an existing string or building up a string in a
886loop:
887
888@example
889 str = reconcat (str, "pre-", str, NULL);
890@end example
891
892@end deftypefn
893
39423523
DD
894@c rename.c:6
895@deftypefn Supplemental int rename (const char *@var{old}, const char *@var{new})
896
897Renames a file from @var{old} to @var{new}. If @var{new} already
898exists, it is removed.
899
900@end deftypefn
901
902@c rindex.c:5
903@deftypefn Supplemental char* rindex (const char *@var{s}, int @var{c})
904
fa9f0e33 905Returns a pointer to the last occurrence of the character @var{c} in
99b58139 906the string @var{s}, or @code{NULL} if not found. The use of @code{rindex} is
39423523
DD
907deprecated in new programs in favor of @code{strrchr}.
908
909@end deftypefn
910
911@c setenv.c:22
912@deftypefn Supplemental int setenv (const char *@var{name}, const char *@var{value}, int @var{overwrite})
913@deftypefnx Supplemental void unsetenv (const char *@var{name})
914
915@code{setenv} adds @var{name} to the environment with value
916@var{value}. If the name was already present in the environment,
56056af5 917the new value will be stored only if @var{overwrite} is nonzero.
39423523
DD
918The companion @code{unsetenv} function removes @var{name} from the
919environment. This implementation is not safe for multithreaded code.
920
921@end deftypefn
922
b109e79a 923@c strsignal.c:348
5d852400 924@deftypefn Extension int signo_max (void)
ba19b94f
DD
925
926Returns the maximum signal value for which a corresponding symbolic
927name or message is available. Note that in the case where we use the
928@code{sys_siglist} supplied by the system, it is possible for there to
929be more symbolic names than messages, or vice versa. In fact, the
930manual page for @code{psignal(3b)} explicitly warns that one should
931check the size of the table (@code{NSIG}) before indexing it, since
932new signal codes may be added to the system before they are added to
933the table. Thus @code{NSIG} might be smaller than value implied by
934the largest signo value defined in @code{<signal.h>}.
935
936We return the maximum value that can be used to obtain a meaningful
937symbolic name or message.
938
939@end deftypefn
940
39423523
DD
941@c sigsetmask.c:8
942@deftypefn Supplemental int sigsetmask (int @var{set})
943
944Sets the signal mask to the one provided in @var{set} and returns
945the old mask (which, for libiberty's implementation, will always
946be the value @code{1}).
947
948@end deftypefn
949
2ed1e5cc
DD
950@c snprintf.c:28
951@deftypefn Supplemental int snprintf (char *@var{buf}, size_t @var{n}, const char *@var{format}, ...)
952
953This function is similar to sprintf, but it will print at most @var{n}
954characters. On error the return value is -1, otherwise it returns the
955number of characters that would have been printed had @var{n} been
956sufficiently large, regardless of the actual value of @var{n}. Note
957some pre-C99 system libraries do not implement this correctly so users
958cannot generally rely on the return value if the system version of
959this function is used.
960
961@end deftypefn
962
ba19b94f
DD
963@c spaces.c:22
964@deftypefn Extension char* spaces (int @var{count})
965
966Returns a pointer to a memory region filled with the specified
967number of spaces and null terminated. The returned pointer is
968valid until at least the next call.
969
970@end deftypefn
971
10b57b38
DD
972@c stpcpy.c:23
973@deftypefn Supplemental char* stpcpy (char *@var{dst}, const char *@var{src})
974
975Copies the string @var{src} into @var{dst}. Returns a pointer to
976@var{dst} + strlen(@var{src}).
977
978@end deftypefn
979
980@c stpncpy.c:23
981@deftypefn Supplemental char* stpncpy (char *@var{dst}, const char *@var{src}, size_t @var{len})
982
983Copies the string @var{src} into @var{dst}, copying exactly @var{len}
984and padding with zeros if necessary. If @var{len} < strlen(@var{src})
985then return @var{dst} + @var{len}, otherwise returns @var{dst} +
986strlen(@var{src}).
987
988@end deftypefn
989
39423523
DD
990@c strcasecmp.c:15
991@deftypefn Supplemental int strcasecmp (const char *@var{s1}, const char *@var{s2})
992
993A case-insensitive @code{strcmp}.
994
995@end deftypefn
996
997@c strchr.c:6
998@deftypefn Supplemental char* strchr (const char *@var{s}, int @var{c})
999
fa9f0e33 1000Returns a pointer to the first occurrence of the character @var{c} in
99b58139 1001the string @var{s}, or @code{NULL} if not found. If @var{c} is itself the
39423523
DD
1002null character, the results are undefined.
1003
1004@end deftypefn
1005
1006@c strdup.c:3
1007@deftypefn Supplemental char* strdup (const char *@var{s})
1008
1009Returns a pointer to a copy of @var{s} in memory obtained from
99b58139 1010@code{malloc}, or @code{NULL} if insufficient memory was available.
39423523
DD
1011
1012@end deftypefn
1013
b109e79a 1014@c strerror.c:670
ba19b94f 1015@deftypefn Replacement {const char*} strerrno (int @var{errnum})
39423523
DD
1016
1017Given an error number returned from a system call (typically returned
1018in @code{errno}), returns a pointer to a string containing the
99b58139 1019symbolic name of that error number, as found in @code{<errno.h>}.
39423523
DD
1020
1021If the supplied error number is within the valid range of indices for
1022symbolic names, but no name is available for the particular error
ba19b94f 1023number, then returns the string @samp{Error @var{num}}, where @var{num}
fa9f0e33 1024is the error number.
39423523
DD
1025
1026If the supplied error number is not within the range of valid
99b58139 1027indices, then returns @code{NULL}.
39423523
DD
1028
1029The contents of the location pointed to are only guaranteed to be
fa9f0e33 1030valid until the next call to @code{strerrno}.
39423523
DD
1031
1032@end deftypefn
1033
b5c3b3de 1034@c strerror.c:603
ba19b94f 1035@deftypefn Supplemental char* strerror (int @var{errnoval})
39423523
DD
1036
1037Maps an @code{errno} number to an error message string, the contents
1038of which are implementation defined. On systems which have the
1039external variables @code{sys_nerr} and @code{sys_errlist}, these
1040strings will be the same as the ones used by @code{perror}.
1041
1042If the supplied error number is within the valid range of indices for
1043the @code{sys_errlist}, but no message is available for the particular
ba19b94f 1044error number, then returns the string @samp{Error @var{num}}, where
fa9f0e33 1045@var{num} is the error number.
39423523
DD
1046
1047If the supplied error number is not a valid index into
99b58139 1048@code{sys_errlist}, returns @code{NULL}.
39423523
DD
1049
1050The returned string is only guaranteed to be valid only until the
1051next call to @code{strerror}.
1052
1053@end deftypefn
1054
1055@c strncasecmp.c:15
1056@deftypefn Supplemental int strncasecmp (const char *@var{s1}, const char *@var{s2})
1057
1058A case-insensitive @code{strncmp}.
1059
1060@end deftypefn
1061
1062@c strncmp.c:6
1063@deftypefn Supplemental int strncmp (const char *@var{s1}, const char *@var{s2}, size_t @var{n})
1064
1065Compares the first @var{n} bytes of two strings, returning a value as
1066@code{strcmp}.
1067
1068@end deftypefn
1069
0fad4bdb
DD
1070@c strndup.c:23
1071@deftypefn Extension char* strndup (const char *@var{s}, size_t @var{n})
1072
1073Returns a pointer to a copy of @var{s} with at most @var{n} characters
1074in memory obtained from @code{malloc}, or @code{NULL} if insufficient
1075memory was available. The result is always NUL terminated.
1076
1077@end deftypefn
1078
39423523
DD
1079@c strrchr.c:6
1080@deftypefn Supplemental char* strrchr (const char *@var{s}, int @var{c})
1081
fa9f0e33 1082Returns a pointer to the last occurrence of the character @var{c} in
99b58139 1083the string @var{s}, or @code{NULL} if not found. If @var{c} is itself the
39423523
DD
1084null character, the results are undefined.
1085
1086@end deftypefn
1087
b109e79a 1088@c strsignal.c:383
ba19b94f
DD
1089@deftypefn Supplemental {const char *} strsignal (int @var{signo})
1090
1091Maps an signal number to an signal message string, the contents of
1092which are implementation defined. On systems which have the external
1093variable @code{sys_siglist}, these strings will be the same as the
1094ones used by @code{psignal()}.
1095
1096If the supplied signal number is within the valid range of indices for
1097the @code{sys_siglist}, but no message is available for the particular
1098signal number, then returns the string @samp{Signal @var{num}}, where
1099@var{num} is the signal number.
1100
1101If the supplied signal number is not a valid index into
1102@code{sys_siglist}, returns @code{NULL}.
1103
1104The returned string is only guaranteed to be valid only until the next
1105call to @code{strsignal}.
1106
1107@end deftypefn
1108
b109e79a 1109@c strsignal.c:446
ba19b94f
DD
1110@deftypefn Extension {const char*} strsigno (int @var{signo})
1111
1112Given an signal number, returns a pointer to a string containing the
1113symbolic name of that signal number, as found in @code{<signal.h>}.
1114
1115If the supplied signal number is within the valid range of indices for
1116symbolic names, but no name is available for the particular signal
1117number, then returns the string @samp{Signal @var{num}}, where
1118@var{num} is the signal number.
1119
1120If the supplied signal number is not within the range of valid
1121indices, then returns @code{NULL}.
1122
1123The contents of the location pointed to are only guaranteed to be
1124valid until the next call to @code{strsigno}.
1125
1126@end deftypefn
1127
39423523
DD
1128@c strstr.c:6
1129@deftypefn Supplemental char* strstr (const char *@var{string}, const char *@var{sub})
1130
1131This function searches for the substring @var{sub} in the string
fa9f0e33 1132@var{string}, not including the terminating null characters. A pointer
99b58139 1133to the first occurrence of @var{sub} is returned, or @code{NULL} if the
39423523
DD
1134substring is absent. If @var{sub} points to a string with zero
1135length, the function returns @var{string}.
1136
1137@end deftypefn
1138
1139@c strtod.c:27
1140@deftypefn Supplemental double strtod (const char *@var{string}, char **@var{endptr})
1141
56056af5 1142This ISO C function converts the initial portion of @var{string} to a
99b58139 1143@code{double}. If @var{endptr} is not @code{NULL}, a pointer to the
39423523
DD
1144character after the last character used in the conversion is stored in
1145the location referenced by @var{endptr}. If no conversion is
1146performed, zero is returned and the value of @var{string} is stored in
1147the location referenced by @var{endptr}.
1148
1149@end deftypefn
1150
b109e79a 1151@c strerror.c:729
ba19b94f 1152@deftypefn Extension int strtoerrno (const char *@var{name})
39423523 1153
99b58139 1154Given the symbolic name of a error number (e.g., @code{EACCES}), map it
39423523
DD
1155to an errno value. If no translation is found, returns 0.
1156
1157@end deftypefn
1158
1159@c strtol.c:33
1160@deftypefn Supplemental {long int} strtol (const char *@var{string}, char **@var{endptr}, int @var{base})
ba19b94f 1161@deftypefnx Supplemental {unsigned long int} strtoul (const char *@var{string}, char **@var{endptr}, int @var{base})
39423523
DD
1162
1163The @code{strtol} function converts the string in @var{string} to a
1164long integer value according to the given @var{base}, which must be
1165between 2 and 36 inclusive, or be the special value 0. If @var{base}
1166is 0, @code{strtol} will look for the prefixes @code{0} and @code{0x}
1167to indicate bases 8 and 16, respectively, else default to base 10.
1168When the base is 16 (either explicitly or implicitly), a prefix of
fa9f0e33 1169@code{0x} is allowed. The handling of @var{endptr} is as that of
ba19b94f
DD
1170@code{strtod} above. The @code{strtoul} function is the same, except
1171that the converted value is unsigned.
1172
1173@end deftypefn
1174
b109e79a 1175@c strsignal.c:500
ba19b94f
DD
1176@deftypefn Extension int strtosigno (const char *@var{name})
1177
1178Given the symbolic name of a signal, map it to a signal number. If no
1179translation is found, returns 0.
39423523
DD
1180
1181@end deftypefn
1182
1183@c tmpnam.c:3
1184@deftypefn Supplemental char* tmpnam (char *@var{s})
1185
1186This function attempts to create a name for a temporary file, which
1187will be a valid file name yet not exist when @code{tmpnam} checks for
1188it. @var{s} must point to a buffer of at least @code{L_tmpnam} bytes,
99b58139 1189or be @code{NULL}. Use of this function creates a security risk, and it must
39423523
DD
1190not be used in new projects. Use @code{mkstemp} instead.
1191
1192@end deftypefn
1193
0fad4bdb
DD
1194@c unlink-if-ordinary.c:27
1195@deftypefn Supplemental int unlink_if_ordinary (const char*)
1196
1197Unlinks the named file, unless it is special (e.g. a device file).
1198Returns 0 when the file was unlinked, a negative value (and errno set) when
1199there was an error deleting the file, and a positive value if no attempt
1200was made to unlink the file because it is special.
1201
1202@end deftypefn
1203
c631edf1
DD
1204@c fopen_unlocked.c:31
1205@deftypefn Extension void unlock_std_streams (void)
1206
1207If the OS supports it, ensure that the standard I/O streams,
1208@code{stdin}, @code{stdout} and @code{stderr} are setup to avoid any
1209multi-threaded locking. Otherwise do nothing.
1210
1211@end deftypefn
1212
7b6f6286
DD
1213@c fopen_unlocked.c:23
1214@deftypefn Extension void unlock_stream (FILE * @var{stream})
1215
1216If the OS supports it, ensure that the supplied stream is setup to
1217avoid any multi-threaded locking. Otherwise leave the @code{FILE}
1218pointer unchanged. If the @var{stream} is @code{NULL} do nothing.
1219
1220@end deftypefn
1221
b109e79a 1222@c vasprintf.c:47
5d852400 1223@deftypefn Extension int vasprintf (char **@var{resptr}, const char *@var{format}, va_list @var{args})
ba19b94f
DD
1224
1225Like @code{vsprintf}, but instead of passing a pointer to a buffer,
1226you pass a pointer to a pointer. This function will compute the size
1227of the buffer needed, allocate memory with @code{malloc}, and store a
1228pointer to the allocated memory in @code{*@var{resptr}}. The value
1229returned is the same as @code{vsprintf} would return. If memory could
5a4e47bd 1230not be allocated, minus one is returned and @code{NULL} is stored in
ba19b94f
DD
1231@code{*@var{resptr}}.
1232
1233@end deftypefn
1234
39423523 1235@c vfork.c:6
99b58139 1236@deftypefn Supplemental int vfork (void)
39423523
DD
1237
1238Emulates @code{vfork} by calling @code{fork} and returning its value.
1239
1240@end deftypefn
1241
1242@c vprintf.c:3
1243@deftypefn Supplemental int vprintf (const char *@var{format}, va_list @var{ap})
1244@deftypefnx Supplemental int vfprintf (FILE *@var{stream}, const char *@var{format}, va_list @var{ap})
1245@deftypefnx Supplemental int vsprintf (char *@var{str}, const char *@var{format}, va_list @var{ap})
1246
1247These functions are the same as @code{printf}, @code{fprintf}, and
1248@code{sprintf}, respectively, except that they are called with a
1249@code{va_list} instead of a variable number of arguments. Note that
1250they do not call @code{va_end}; this is the application's
1251responsibility. In @libib{} they are implemented in terms of the
1252nonstandard but common function @code{_doprnt}.
1253
1254@end deftypefn
1255
2ed1e5cc
DD
1256@c vsnprintf.c:28
1257@deftypefn Supplemental int vsnprintf (char *@var{buf}, size_t @var{n}, const char *@var{format}, va_list @var{ap})
1258
1259This function is similar to vsprintf, but it will print at most
1260@var{n} characters. On error the return value is -1, otherwise it
1261returns the number of characters that would have been printed had
1262@var{n} been sufficiently large, regardless of the actual value of
1263@var{n}. Note some pre-C99 system libraries do not implement this
1264correctly so users cannot generally rely on the return value if the
1265system version of this function is used.
1266
1267@end deftypefn
1268
39423523
DD
1269@c waitpid.c:3
1270@deftypefn Supplemental int waitpid (int @var{pid}, int *@var{status}, int)
1271
1272This is a wrapper around the @code{wait} function. Any ``special''
1273values of @var{pid} depend on your implementation of @code{wait}, as
1274does the return value. The third argument is unused in @libib{}.
1275
1276@end deftypefn
1277
1278@c xatexit.c:11
1279@deftypefun int xatexit (void (*@var{fn}) (void))
1280
1281Behaves as the standard @code{atexit} function, but with no limit on
99b58139 1282the number of registered functions. Returns 0 on success, or @minus{}1 on
39423523
DD
1283failure. If you use @code{xatexit} to register functions, you must use
1284@code{xexit} to terminate your program.
1285
1286@end deftypefun
1287
fa9f0e33 1288@c xmalloc.c:38
99b58139 1289@deftypefn Replacement void* xcalloc (size_t @var{nelem}, size_t @var{elsize})
39423523
DD
1290
1291Allocate memory without fail, and set it to zero. This routine functions
1292like @code{calloc}, but will behave the same as @code{xmalloc} if memory
1293cannot be found.
1294
1295@end deftypefn
1296
1297@c xexit.c:22
1298@deftypefn Replacement void xexit (int @var{code})
1299
1300Terminates the program. If any functions have been registered with
fa9f0e33 1301the @code{xatexit} replacement function, they will be called first.
39423523
DD
1302Termination is handled via the system's normal @code{exit} call.
1303
1304@end deftypefn
1305
1306@c xmalloc.c:22
1307@deftypefn Replacement void* xmalloc (size_t)
1308
1309Allocate memory without fail. If @code{malloc} fails, this will print
fa9f0e33
DD
1310a message to @code{stderr} (using the name set by
1311@code{xmalloc_set_program_name},
39423523
DD
1312if any) and then call @code{xexit}. Note that it is therefore safe for
1313a program to contain @code{#define malloc xmalloc} in its source.
1314
1315@end deftypefn
1316
fa9f0e33 1317@c xmalloc.c:53
39423523
DD
1318@deftypefn Replacement void xmalloc_failed (size_t)
1319
1320This function is not meant to be called by client code, and is listed
1321here for completeness only. If any of the allocation routines fail, this
1322function will be called to print an error message and terminate execution.
1323
1324@end deftypefn
1325
fa9f0e33 1326@c xmalloc.c:46
39423523
DD
1327@deftypefn Replacement void xmalloc_set_program_name (const char *@var{name})
1328
1329You can use this to set the name of the program used by
1330@code{xmalloc_failed} when printing a failure message.
1331
1332@end deftypefn
1333
1334@c xmemdup.c:7
1335@deftypefn Replacement void* xmemdup (void *@var{input}, size_t @var{copy_size}, size_t @var{alloc_size})
1336
1337Duplicates a region of memory without fail. First, @var{alloc_size} bytes
1338are allocated, then @var{copy_size} bytes from @var{input} are copied into
1339it, and the new memory is returned. If fewer bytes are copied than were
1340allocated, the remaining memory is zeroed.
1341
1342@end deftypefn
1343
fa9f0e33 1344@c xmalloc.c:32
99b58139 1345@deftypefn Replacement void* xrealloc (void *@var{ptr}, size_t @var{size})
39423523
DD
1346Reallocate memory without fail. This routine functions like @code{realloc},
1347but will behave the same as @code{xmalloc} if memory cannot be found.
1348
1349@end deftypefn
1350
1351@c xstrdup.c:7
1352@deftypefn Replacement char* xstrdup (const char *@var{s})
1353
1354Duplicates a character string without fail, using @code{xmalloc} to
1355obtain memory.
1356
1357@end deftypefn
1358
1359@c xstrerror.c:7
1360@deftypefn Replacement char* xstrerror (int @var{errnum})
1361
1362Behaves exactly like the standard @code{strerror} function, but
99b58139 1363will never return a @code{NULL} pointer.
39423523
DD
1364
1365@end deftypefn
1366
0fad4bdb
DD
1367@c xstrndup.c:23
1368@deftypefn Replacement char* xstrndup (const char *@var{s}, size_t @var{n})
1369
1370Returns a pointer to a copy of @var{s} with at most @var{n} characters
1371without fail, using @code{xmalloc} to obtain memory. The result is
1372always NUL terminated.
1373
1374@end deftypefn
1375
39423523 1376