]> git.ipfire.org Git - thirdparty/gcc.git/blame - libiberty/functions.texi
libiberty: Expose choose_tmpdir, and fix constness of return type
[thirdparty/gcc.git] / libiberty / functions.texi
CommitLineData
aaa5f039
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,
1dd2c57b 4@c run 'make stamp-functions' and gather-docs will build a new copy.
aaa5f039
DD
5
6@c alloca.c:26
7f8fa05d 7@deftypefn Replacement void* alloca (size_t @var{size})
aaa5f039
DD
8
9This function allocates memory which will be automatically reclaimed
10after the procedure exits. The @libib{} implementation does not free
11the memory immediately but will do so eventually during subsequent
12calls to this function. Memory is allocated using @code{xmalloc} under
13normal circumstances.
14
15The header file @file{alloca-conf.h} can be used in conjunction with the
16GNU Autoconf test @code{AC_FUNC_ALLOCA} to test for and properly make
17available this function. The @code{AC_FUNC_ALLOCA} test requires that
18client code use a block of preprocessor code to be safe (see the Autoconf
19manual for more); this header incorporates that logic and more, including
7f8fa05d 20the possibility of a GCC built-in function.
aaa5f039
DD
21
22@end deftypefn
23
32e82bd8 24@c asprintf.c:32
5bed56d9 25@deftypefn Extension int asprintf (char **@var{resptr}, const char *@var{format}, ...)
aac04c15
DD
26
27Like @code{sprintf}, but instead of passing a pointer to a buffer, you
28pass a pointer to a pointer. This function will compute the size of
29the buffer needed, allocate memory with @code{malloc}, and store a
30pointer to the allocated memory in @code{*@var{resptr}}. The value
31returned is the same as @code{sprintf} would return. If memory could
8d398258 32not be allocated, minus one is returned and @code{NULL} is stored in
aac04c15
DD
33@code{*@var{resptr}}.
34
35@end deftypefn
36
aaa5f039
DD
37@c atexit.c:6
38@deftypefn Supplemental int atexit (void (*@var{f})())
39
40Causes function @var{f} to be called at exit. Returns 0.
41
42@end deftypefn
43
44@c basename.c:6
45@deftypefn Supplemental char* basename (const char *@var{name})
46
47Returns a pointer to the last component of pathname @var{name}.
48Behavior is undefined if the pathname ends in a directory separator.
49
50@end deftypefn
51
52@c bcmp.c:6
53@deftypefn Supplemental int bcmp (char *@var{x}, char *@var{y}, int @var{count})
54
55Compares the first @var{count} bytes of two areas of memory. Returns
0e4e9e8f
JM
56zero if they are the same, nonzero otherwise. Returns zero if
57@var{count} is zero. A nonzero result only indicates a difference,
aaa5f039
DD
58it does not indicate any sorting order (say, by having a positive
59result mean @var{x} sorts before @var{y}).
60
61@end deftypefn
62
63@c bcopy.c:3
64@deftypefn Supplemental void bcopy (char *@var{in}, char *@var{out}, int @var{length})
65
66Copies @var{length} bytes from memory region @var{in} to region
67@var{out}. The use of @code{bcopy} is deprecated in new programs.
68
69@end deftypefn
70
71@c bsearch.c:33
996c0cb0
RW
72@deftypefn Supplemental void* bsearch (const void *@var{key}, @
73 const void *@var{base}, size_t @var{nmemb}, size_t @var{size}, @
74 int (*@var{compar})(const void *, const void *))
aaa5f039
DD
75
76Performs a search over an array of @var{nmemb} elements pointed to by
77@var{base} for a member that matches the object pointed to by @var{key}.
78The size of each member is specified by @var{size}. The array contents
79should be sorted in ascending order according to the @var{compar}
80comparison function. This routine should take two arguments pointing to
81the @var{key} and to an array member, in that order, and should return an
82integer less than, equal to, or greater than zero if the @var{key} object
ae9092da 83is respectively less than, matching, or greater than the array member.
aaa5f039
DD
84
85@end deftypefn
86
9a9baa52 87@c argv.c:135
aac04c15
DD
88@deftypefn Extension char** buildargv (char *@var{sp})
89
90Given a pointer to a string, parse the string extracting fields
91separated by whitespace and optionally enclosed within either single
92or double quotes (which are stripped off), and build a vector of
93pointers to copies of the string for each field. The input string
94remains unchanged. The last element of the vector is followed by a
95@code{NULL} element.
96
97All of the memory for the pointer array and copies of the string
9a9baa52 98is obtained from @code{xmalloc}. All of the memory can be returned to the
aac04c15
DD
99system with the single function call @code{freeargv}, which takes the
100returned result of @code{buildargv}, as it's argument.
101
5bed56d9 102Returns a pointer to the argument vector if successful. Returns
aac04c15
DD
103@code{NULL} if @var{sp} is @code{NULL} or if there is insufficient
104memory to complete building the argument vector.
105
106If the input is a null string (as opposed to a @code{NULL} pointer),
107then buildarg returns an argument vector that has one arg, a null
108string.
109
110@end deftypefn
111
aaa5f039
DD
112@c bzero.c:6
113@deftypefn Supplemental void bzero (char *@var{mem}, int @var{count})
114
ae9092da 115Zeros @var{count} bytes starting at @var{mem}. Use of this function
aaa5f039
DD
116is deprecated in favor of @code{memset}.
117
118@end deftypefn
119
120@c calloc.c:6
121@deftypefn Supplemental void* calloc (size_t @var{nelem}, size_t @var{elsize})
122
123Uses @code{malloc} to allocate storage for @var{nelem} objects of
124@var{elsize} bytes each, then zeros the memory.
125
126@end deftypefn
127
e39423c0 128@c choose-temp.c:45
5bed56d9 129@deftypefn Extension char* choose_temp_base (void)
aac04c15
DD
130
131Return a prefix for temporary file names or @code{NULL} if unable to
132find one. The current directory is chosen if all else fails so the
133program is exited if a temporary directory can't be found (@code{mktemp}
134fails). The buffer for the result is obtained with @code{xmalloc}.
135
15b16eb5 136This function is provided for backwards compatibility only. Its use is
aac04c15
DD
137not recommended.
138
139@end deftypefn
140
996c0cb0 141@c make-temp-file.c:96
e39423c0 142@deftypefn Replacement const char* choose_tmpdir ()
aac04c15
DD
143
144Returns a pointer to a directory path suitable for creating temporary
145files in.
146
147@end deftypefn
148
aaa5f039 149@c clock.c:27
7f8fa05d 150@deftypefn Supplemental long clock (void)
aaa5f039
DD
151
152Returns an approximation of the CPU time used by the process as a
153@code{clock_t}; divide this number by @samp{CLOCKS_PER_SEC} to get the
154number of seconds used.
155
156@end deftypefn
157
aac04c15 158@c concat.c:24
996c0cb0
RW
159@deftypefn Extension char* concat (const char *@var{s1}, const char *@var{s2}, @
160 @dots{}, @code{NULL})
aac04c15
DD
161
162Concatenate zero or more of strings and return the result in freshly
e39423c0
DM
163@code{xmalloc}ed memory. The argument list is terminated by the first
164@code{NULL} pointer encountered. Pointers to empty strings are ignored.
aac04c15
DD
165
166@end deftypefn
167
9a9baa52
ILT
168@c argv.c:470
169@deftypefn Extension int countargv (char **@var{argv})
170
171Return the number of elements in @var{argv}.
172Returns zero if @var{argv} is NULL.
173
174@end deftypefn
175
b524249c 176@c crc32.c:141
996c0cb0
RW
177@deftypefn Extension {unsigned int} crc32 (const unsigned char *@var{buf}, @
178 int @var{len}, unsigned int @var{init})
b524249c
ILT
179
180Compute the 32-bit CRC of @var{buf} which has length @var{len}. The
181starting value is @var{init}; this may be used to compute the CRC of
182data split across multiple buffers by passing the return value of each
183call as the @var{init} parameter of the next.
184
185This is intended to match the CRC used by the @command{gdb} remote
186protocol for the @samp{qCRC} command. In order to get the same
187results as gdb for a block of data, you must pass the first CRC
188parameter as @code{0xffffffff}.
189
1dd2c57b
BE
190This CRC can be specified as:
191
192 Width : 32
193 Poly : 0x04c11db7
194 Init : parameter, typically 0xffffffff
195 RefIn : false
196 RefOut : false
197 XorOut : 0
198
199This differs from the "standard" CRC-32 algorithm in that the values
200are not reflected, and there is no final XOR value. These differences
201make it easy to compose the values of multiple blocks.
202
b524249c
ILT
203@end deftypefn
204
32e82bd8 205@c argv.c:52
aac04c15
DD
206@deftypefn Extension char** dupargv (char **@var{vector})
207
208Duplicate an argument vector. Simply scans through @var{vector},
209duplicating each argument until the terminating @code{NULL} is found.
5bed56d9 210Returns a pointer to the argument vector if successful. Returns
aac04c15
DD
211@code{NULL} if there is insufficient memory to complete building the
212argument vector.
213
214@end deftypefn
215
e8805990 216@c strerror.c:567
aac04c15 217@deftypefn Extension int errno_max (void)
aaa5f039
DD
218
219Returns the maximum @code{errno} value for which a corresponding
220symbolic name or message is available. Note that in the case where we
221use the @code{sys_errlist} supplied by the system, it is possible for
222there to be more symbolic names than messages, or vice versa. In
223fact, the manual page for @code{perror(3C)} explicitly warns that one
224should check the size of the table (@code{sys_nerr}) before indexing
225it, since new error codes may be added to the system before they are
226added to the table. Thus @code{sys_nerr} might be smaller than value
7f8fa05d 227implied by the largest @code{errno} value defined in @code{<errno.h>}.
aaa5f039
DD
228
229We return the maximum value that can be used to obtain a meaningful
230symbolic name or message.
231
232@end deftypefn
233
9a9baa52 234@c argv.c:341
ddbbee51
JB
235@deftypefn Extension void expandargv (int *@var{argcp}, char ***@var{argvp})
236
237The @var{argcp} and @code{argvp} arguments are pointers to the usual
238@code{argc} and @code{argv} arguments to @code{main}. This function
239looks for arguments that begin with the character @samp{@@}. Any such
240arguments are interpreted as ``response files''. The contents of the
241response file are interpreted as additional command line options. In
242particular, the file is separated into whitespace-separated strings;
243each such string is taken as a command-line option. The new options
244are inserted in place of the option naming the response file, and
245@code{*argcp} and @code{*argvp} will be updated. If the value of
246@code{*argvp} is modified by this function, then the new value has
247been dynamically allocated and can be deallocated by the caller with
248@code{freeargv}. However, most callers will simply call
249@code{expandargv} near the beginning of @code{main} and allow the
250operating system to free the memory when the program exits.
251
252@end deftypefn
253
aac04c15
DD
254@c fdmatch.c:23
255@deftypefn Extension int fdmatch (int @var{fd1}, int @var{fd2})
256
257Check to see if two open file descriptors refer to the same file.
258This is useful, for example, when we have an open file descriptor for
259an unnamed file, and the name of a file that we believe to correspond
260to that fd. This can happen when we are exec'd with an already open
261file (@code{stdout} for example) or from the SVR4 @file{/proc} calls
262that return open file descriptors for mapped address spaces. All we
263have to do is open the file by name and check the two file descriptors
264for a match, which is done by comparing major and minor device numbers
265and inode numbers.
266
267@end deftypefn
268
996c0cb0
RW
269@c fopen_unlocked.c:49
270@deftypefn Extension {FILE *} fdopen_unlocked (int @var{fildes}, @
271 const char * @var{mode})
78a7dc90
KG
272
273Opens and returns a @code{FILE} pointer via @code{fdopen}. If the
274operating system supports it, ensure that the stream is setup to avoid
275any multi-threaded locking. Otherwise return the @code{FILE} pointer
276unchanged.
277
278@end deftypefn
279
aac04c15
DD
280@c ffs.c:3
281@deftypefn Supplemental int ffs (int @var{valu})
282
5bed56d9 283Find the first (least significant) bit set in @var{valu}. Bits are
aac04c15
DD
284numbered from right to left, starting with bit 1 (corresponding to the
285value 1). If @var{valu} is zero, zero is returned.
286
287@end deftypefn
288
f4e00f44 289@c filename_cmp.c:32
cde515d9
JB
290@deftypefn Extension int filename_cmp (const char *@var{s1}, const char *@var{s2})
291
f4e00f44
DD
292Return zero if the two file names @var{s1} and @var{s2} are equivalent.
293If not equivalent, the returned value is similar to what @code{strcmp}
294would return. In other words, it returns a negative value if @var{s1}
295is less than @var{s2}, or a positive value if @var{s2} is greater than
296@var{s2}.
cde515d9 297
f4e00f44 298This function does not normalize file names. As a result, this function
94369251
KT
299will treat filenames that are spelled differently as different even in
300the case when the two filenames point to the same underlying file.
301However, it does handle the fact that on DOS-like file systems, forward
302and backward slashes are equal.
303
304@end deftypefn
305
9a9baa52
ILT
306@c filename_cmp.c:178
307@deftypefn Extension int filename_eq (const void *@var{s1}, const void *@var{s2})
308
309Return non-zero if file names @var{s1} and @var{s2} are equivalent.
310This function is for use with hashtab.c hash tables.
311
312@end deftypefn
313
314@c filename_cmp.c:147
315@deftypefn Extension hashval_t filename_hash (const void *@var{s})
316
317Return the hash value for file name @var{s} that will be compared
318using filename_cmp.
319This function is for use with hashtab.c hash tables.
320
321@end deftypefn
322
323@c filename_cmp.c:89
94369251
KT
324@deftypefn Extension int filename_ncmp (const char *@var{s1}, const char *@var{s2}, size_t @var{n})
325
326Return zero if the two file names @var{s1} and @var{s2} are equivalent
327in range @var{n}.
328If not equivalent, the returned value is similar to what @code{strncmp}
329would return. In other words, it returns a negative value if @var{s1}
330is less than @var{s2}, or a positive value if @var{s2} is greater than
331@var{s2}.
332
333This function does not normalize file names. As a result, this function
cde515d9
JB
334will treat filenames that are spelled differently as different even in
335the case when the two filenames point to the same underlying file.
336However, it does handle the fact that on DOS-like file systems, forward
337and backward slashes are equal.
338
339@end deftypefn
340
aac04c15 341@c fnmatch.txh:1
996c0cb0
RW
342@deftypefn Replacement int fnmatch (const char *@var{pattern}, @
343 const char *@var{string}, int @var{flags})
aac04c15
DD
344
345Matches @var{string} against @var{pattern}, returning zero if it
346matches, @code{FNM_NOMATCH} if not. @var{pattern} may contain the
347wildcards @code{?} to match any one character, @code{*} to match any
348zero or more characters, or a set of alternate characters in square
349brackets, like @samp{[a-gt8]}, which match one character (@code{a}
350through @code{g}, or @code{t}, or @code{8}, in this example) if that one
5bed56d9 351character is in the set. A set may be inverted (i.e., match anything
aac04c15
DD
352except what's in the set) by giving @code{^} or @code{!} as the first
353character in the set. To include those characters in the set, list them
354as anything other than the first character of the set. To include a
355dash in the set, list it last in the set. A backslash character makes
356the following character not special, so for example you could match
357against a literal asterisk with @samp{\*}. To match a literal
358backslash, use @samp{\\}.
359
360@code{flags} controls various aspects of the matching process, and is a
361boolean OR of zero or more of the following values (defined in
5bed56d9 362@code{<fnmatch.h>}):
aac04c15
DD
363
364@table @code
365
366@item FNM_PATHNAME
367@itemx FNM_FILE_NAME
368@var{string} is assumed to be a path name. No wildcard will ever match
369@code{/}.
370
371@item FNM_NOESCAPE
372Do not interpret backslashes as quoting the following special character.
373
374@item FNM_PERIOD
375A leading period (at the beginning of @var{string}, or if
376@code{FNM_PATHNAME} after a slash) is not matched by @code{*} or
377@code{?} but must be matched explicitly.
378
379@item FNM_LEADING_DIR
380Means that @var{string} also matches @var{pattern} if some initial part
381of @var{string} matches, and is followed by @code{/} and zero or more
382characters. For example, @samp{foo*} would match either @samp{foobar}
383or @samp{foobar/grill}.
384
385@item FNM_CASEFOLD
386Ignores case when performing the comparison.
387
388@end table
389
390@end deftypefn
391
32e82bd8 392@c fopen_unlocked.c:39
996c0cb0
RW
393@deftypefn Extension {FILE *} fopen_unlocked (const char *@var{path}, @
394 const char * @var{mode})
78a7dc90
KG
395
396Opens and returns a @code{FILE} pointer via @code{fopen}. If the
397operating system supports it, ensure that the stream is setup to avoid
398any multi-threaded locking. Otherwise return the @code{FILE} pointer
399unchanged.
400
401@end deftypefn
402
9a9baa52 403@c argv.c:90
aac04c15
DD
404@deftypefn Extension void freeargv (char **@var{vector})
405
406Free an argument vector that was built using @code{buildargv}. Simply
407scans through @var{vector}, freeing the memory for each argument until
408the terminating @code{NULL} is found, and then frees @var{vector}
409itself.
410
411@end deftypefn
412
996c0cb0
RW
413@c fopen_unlocked.c:59
414@deftypefn Extension {FILE *} freopen_unlocked (const char * @var{path}, @
415 const char * @var{mode}, FILE * @var{stream})
78a7dc90
KG
416
417Opens and returns a @code{FILE} pointer via @code{freopen}. If the
418operating system supports it, ensure that the stream is setup to avoid
419any multi-threaded locking. Otherwise return the @code{FILE} pointer
420unchanged.
421
422@end deftypefn
423
42766f8d 424@c getruntime.c:82
5bed56d9 425@deftypefn Replacement long get_run_time (void)
aac04c15
DD
426
427Returns the time used so far, in microseconds. If possible, this is
428the time used by this process, else it is the elapsed time since the
429process started.
430
431@end deftypefn
432
aaa5f039 433@c getcwd.c:6
7f8fa05d 434@deftypefn Supplemental char* getcwd (char *@var{pathname}, int @var{len})
aaa5f039
DD
435
436Copy the absolute pathname for the current working directory into
437@var{pathname}, which is assumed to point to a buffer of at least
438@var{len} bytes, and return a pointer to the buffer. If the current
439directory's path doesn't fit in @var{len} characters, the result is
7f8fa05d 440@code{NULL} and @code{errno} is set. If @var{pathname} is a null pointer,
aaa5f039
DD
441@code{getcwd} will obtain @var{len} bytes of space using
442@code{malloc}.
443
444@end deftypefn
445
446@c getpagesize.c:5
7f8fa05d 447@deftypefn Supplemental int getpagesize (void)
aaa5f039
DD
448
449Returns the number of bytes in a page of memory. This is the
450granularity of many of the system memory management routines. No
451guarantee is made as to whether or not it is the same as the basic
452memory management hardware page size.
453
454@end deftypefn
455
456@c getpwd.c:5
7f8fa05d 457@deftypefn Supplemental char* getpwd (void)
aaa5f039
DD
458
459Returns the current working directory. This implementation caches the
460result on the assumption that the process will not call @code{chdir}
461between calls to @code{getpwd}.
462
463@end deftypefn
464
17998b22 465@c gettimeofday.c:12
1e3a2100 466@deftypefn Supplemental int gettimeofday (struct timeval *@var{tp}, void *@var{tz})
17998b22
KG
467
468Writes the current time to @var{tp}. This implementation requires
469that @var{tz} be NULL. Returns 0 on success, -1 on failure.
470
471@end deftypefn
472
32e82bd8 473@c hex.c:33
96adcacb
DD
474@deftypefn Extension void hex_init (void)
475
476Initializes the array mapping the current character set to
477corresponding hex values. This function must be called before any
42766f8d
DJ
478call to @code{hex_p} or @code{hex_value}. If you fail to call it, a
479default ASCII-based table will normally be used on ASCII systems.
96adcacb
DD
480
481@end deftypefn
482
32e82bd8 483@c hex.c:42
96adcacb
DD
484@deftypefn Extension int hex_p (int @var{c})
485
486Evaluates to non-zero if the given character is a valid hex character,
487or zero if it is not. Note that the value you pass will be cast to
488@code{unsigned char} within the macro.
489
490@end deftypefn
491
32e82bd8 492@c hex.c:50
e8805990 493@deftypefn Extension {unsigned int} hex_value (int @var{c})
96adcacb
DD
494
495Returns the numeric equivalent of the given character when interpreted
15b16eb5 496as a hexadecimal digit. The result is undefined if you pass an
96adcacb
DD
497invalid hex digit. Note that the value you pass will be cast to
498@code{unsigned char} within the macro.
499
49a19cfd
JB
500The @code{hex_value} macro returns @code{unsigned int}, rather than
501signed @code{int}, to make it easier to use in parsing addresses from
502hex dump files: a signed @code{int} would be sign-extended when
503converted to a wider unsigned type --- like @code{bfd_vma}, on some
504systems.
505
96adcacb
DD
506@end deftypefn
507
996c0cb0
RW
508@c safe-ctype.c:25
509@defvr Extension HOST_CHARSET
510This macro indicates the basic character set and encoding used by the
511host: more precisely, the encoding used for character constants in
512preprocessor @samp{#if} statements (the C "execution character set").
513It is defined by @file{safe-ctype.h}, and will be an integer constant
514with one of the following values:
515
516@ftable @code
517@item HOST_CHARSET_UNKNOWN
518The host character set is unknown - that is, not one of the next two
519possibilities.
520
521@item HOST_CHARSET_ASCII
522The host character set is ASCII.
523
524@item HOST_CHARSET_EBCDIC
525The host character set is some variant of EBCDIC. (Only one of the
526nineteen EBCDIC varying characters is tested; exercise caution.)
527@end ftable
528@end defvr
529
e39423c0 530@c hashtab.c:328
996c0cb0
RW
531@deftypefn Supplemental htab_t htab_create_typed_alloc (size_t @var{size}, @
532htab_hash @var{hash_f}, htab_eq @var{eq_f}, htab_del @var{del_f}, @
533htab_alloc @var{alloc_tab_f}, htab_alloc @var{alloc_f}, @
a9429e29
LB
534htab_free @var{free_f})
535
536This function creates a hash table that uses two different allocators
537@var{alloc_tab_f} and @var{alloc_f} to use for allocating the table itself
538and its entries respectively. This is useful when variables of different
539types need to be allocated with different allocators.
540
541The created hash table is slightly larger than @var{size} and it is
542initially empty (all the hash table entries are @code{HTAB_EMPTY_ENTRY}).
543The function returns the created hash table, or @code{NULL} if memory
544allocation fails.
545
546@end deftypefn
547
aaa5f039
DD
548@c index.c:5
549@deftypefn Supplemental char* index (char *@var{s}, int @var{c})
550
e922f978 551Returns a pointer to the first occurrence of the character @var{c} in
7f8fa05d 552the string @var{s}, or @code{NULL} if not found. The use of @code{index} is
aaa5f039
DD
553deprecated in new programs in favor of @code{strchr}.
554
555@end deftypefn
556
aac04c15 557@c insque.c:6
996c0cb0
RW
558@deftypefn Supplemental void insque (struct qelem *@var{elem}, @
559 struct qelem *@var{pred})
aac04c15
DD
560@deftypefnx Supplemental void remque (struct qelem *@var{elem})
561
562Routines to manipulate queues built from doubly linked lists. The
563@code{insque} routine inserts @var{elem} in the queue immediately
564after @var{pred}. The @code{remque} routine removes @var{elem} from
565its containing queue. These routines expect to be passed pointers to
566structures which have as their first members a forward pointer and a
567back pointer, like this prototype (although no prototype is provided):
568
569@example
570struct qelem @{
571 struct qelem *q_forw;
572 struct qelem *q_back;
573 char q_data[];
574@};
575@end example
576
577@end deftypefn
578
a584cf65 579@c safe-ctype.c:46
21299dbd
ZW
580@deffn Extension ISALPHA (@var{c})
581@deffnx Extension ISALNUM (@var{c})
582@deffnx Extension ISBLANK (@var{c})
583@deffnx Extension ISCNTRL (@var{c})
584@deffnx Extension ISDIGIT (@var{c})
585@deffnx Extension ISGRAPH (@var{c})
586@deffnx Extension ISLOWER (@var{c})
587@deffnx Extension ISPRINT (@var{c})
588@deffnx Extension ISPUNCT (@var{c})
589@deffnx Extension ISSPACE (@var{c})
590@deffnx Extension ISUPPER (@var{c})
591@deffnx Extension ISXDIGIT (@var{c})
592
593These twelve macros are defined by @file{safe-ctype.h}. Each has the
594same meaning as the corresponding macro (with name in lowercase)
595defined by the standard header @file{ctype.h}. For example,
596@code{ISALPHA} returns true for alphabetic characters and false for
597others. However, there are two differences between these macros and
598those provided by @file{ctype.h}:
599
600@itemize @bullet
601@item These macros are guaranteed to have well-defined behavior for all
602values representable by @code{signed char} and @code{unsigned char}, and
603for @code{EOF}.
604
605@item These macros ignore the current locale; they are true for these
606fixed sets of characters:
607@multitable {@code{XDIGIT}} {yada yada yada yada yada yada yada yada}
608@item @code{ALPHA} @tab @kbd{A-Za-z}
609@item @code{ALNUM} @tab @kbd{A-Za-z0-9}
610@item @code{BLANK} @tab @kbd{space tab}
611@item @code{CNTRL} @tab @code{!PRINT}
612@item @code{DIGIT} @tab @kbd{0-9}
613@item @code{GRAPH} @tab @code{ALNUM || PUNCT}
614@item @code{LOWER} @tab @kbd{a-z}
615@item @code{PRINT} @tab @code{GRAPH ||} @kbd{space}
616@item @code{PUNCT} @tab @kbd{`~!@@#$%^&*()_-=+[@{]@}\|;:'",<.>/?}
617@item @code{SPACE} @tab @kbd{space tab \n \r \f \v}
618@item @code{UPPER} @tab @kbd{A-Z}
619@item @code{XDIGIT} @tab @kbd{0-9A-Fa-f}
620@end multitable
621
622Note that, if the host character set is ASCII or a superset thereof,
623all these macros will return false for all values of @code{char} outside
624the range of 7-bit ASCII. In particular, both ISPRINT and ISCNTRL return
625false for characters with numeric values from 128 to 255.
626@end itemize
627@end deffn
628
a584cf65 629@c safe-ctype.c:95
21299dbd
ZW
630@deffn Extension ISIDNUM (@var{c})
631@deffnx Extension ISIDST (@var{c})
632@deffnx Extension IS_VSPACE (@var{c})
633@deffnx Extension IS_NVSPACE (@var{c})
634@deffnx Extension IS_SPACE_OR_NUL (@var{c})
635@deffnx Extension IS_ISOBASIC (@var{c})
636These six macros are defined by @file{safe-ctype.h} and provide
637additional character classes which are useful when doing lexical
638analysis of C or similar languages. They are true for the following
639sets of characters:
640
641@multitable {@code{SPACE_OR_NUL}} {yada yada yada yada yada yada yada yada}
642@item @code{IDNUM} @tab @kbd{A-Za-z0-9_}
643@item @code{IDST} @tab @kbd{A-Za-z_}
644@item @code{VSPACE} @tab @kbd{\r \n}
645@item @code{NVSPACE} @tab @kbd{space tab \f \v \0}
646@item @code{SPACE_OR_NUL} @tab @code{VSPACE || NVSPACE}
647@item @code{ISOBASIC} @tab @code{VSPACE || NVSPACE || PRINT}
648@end multitable
649@end deffn
650
aac04c15
DD
651@c lbasename.c:23
652@deftypefn Replacement {const char*} lbasename (const char *@var{name})
653
654Given a pointer to a string containing a typical pathname
655(@samp{/usr/src/cmd/ls/ls.c} for example), returns a pointer to the
656last component of the pathname (@samp{ls.c} in this case). The
657returned pointer is guaranteed to lie within the original
658string. This latter fact is not true of many vendor C
659libraries, which return special strings or modify the passed
660strings for particular input.
661
662In particular, the empty string returns the same empty string,
663and a path ending in @code{/} returns the empty string after it.
664
665@end deftypefn
666
4876b2b4
DJ
667@c lrealpath.c:25
668@deftypefn Replacement {const char*} lrealpath (const char *@var{name})
669
670Given a pointer to a string containing a pathname, returns a canonical
671version of the filename. Symlinks will be resolved, and ``.'' and ``..''
672components will be simplified. The returned value will be allocated using
029bcc09 673@code{malloc}, or @code{NULL} will be returned on a memory allocation error.
42766f8d 674
4876b2b4 675@end deftypefn
42766f8d 676
4876b2b4 677@c make-relative-prefix.c:24
996c0cb0
RW
678@deftypefn Extension {const char*} make_relative_prefix (const char *@var{progname}, @
679 const char *@var{bin_prefix}, const char *@var{prefix})
42766f8d 680
4876b2b4
DJ
681Given three paths @var{progname}, @var{bin_prefix}, @var{prefix},
682return the path that is in the same position relative to
683@var{progname}'s directory as @var{prefix} is relative to
684@var{bin_prefix}. That is, a string starting with the directory
685portion of @var{progname}, followed by a relative pathname of the
686difference between @var{bin_prefix} and @var{prefix}.
687
688If @var{progname} does not contain any directory separators,
689@code{make_relative_prefix} will search @env{PATH} to find a program
690named @var{progname}. Also, if @var{progname} is a symbolic link,
691the symbolic link will be resolved.
692
693For example, if @var{bin_prefix} is @code{/alpha/beta/gamma/gcc/delta},
694@var{prefix} is @code{/alpha/beta/gamma/omega/}, and @var{progname} is
695@code{/red/green/blue/gcc}, then this function will return
696@code{/red/green/blue/../../omega/}.
697
698The return value is normally allocated via @code{malloc}. If no
699relative prefix can be found, return @code{NULL}.
42766f8d
DJ
700
701@end deftypefn
702
996c0cb0 703@c make-temp-file.c:174
aac04c15
DD
704@deftypefn Replacement char* make_temp_file (const char *@var{suffix})
705
706Return a temporary file name (as a string) or @code{NULL} if unable to
707create one. @var{suffix} is a suffix to append to the file name. The
5bed56d9 708string is @code{malloc}ed, and the temporary file has been created.
aac04c15
DD
709
710@end deftypefn
711
aaa5f039 712@c memchr.c:3
996c0cb0
RW
713@deftypefn Supplemental void* memchr (const void *@var{s}, int @var{c}, @
714 size_t @var{n})
aaa5f039 715
7f8fa05d 716This function searches memory starting at @code{*@var{s}} for the
aaa5f039
DD
717character @var{c}. The search only ends with the first occurrence of
718@var{c}, or after @var{length} characters; in particular, a null
719character does not terminate the search. If the character @var{c} is
7f8fa05d
JM
720found within @var{length} characters of @code{*@var{s}}, a pointer
721to the character is returned. If @var{c} is not found, then @code{NULL} is
aaa5f039
DD
722returned.
723
724@end deftypefn
725
726@c memcmp.c:6
996c0cb0
RW
727@deftypefn Supplemental int memcmp (const void *@var{x}, const void *@var{y}, @
728 size_t @var{count})
aaa5f039
DD
729
730Compares the first @var{count} bytes of two areas of memory. Returns
731zero if they are the same, a value less than zero if @var{x} is
732lexically less than @var{y}, or a value greater than zero if @var{x}
733is lexically greater than @var{y}. Note that lexical order is determined
734as if comparing unsigned char arrays.
735
736@end deftypefn
737
738@c memcpy.c:6
996c0cb0
RW
739@deftypefn Supplemental void* memcpy (void *@var{out}, const void *@var{in}, @
740 size_t @var{length})
aaa5f039
DD
741
742Copies @var{length} bytes from memory region @var{in} to region
743@var{out}. Returns a pointer to @var{out}.
744
745@end deftypefn
746
5fbd9447 747@c memmem.c:20
996c0cb0
RW
748@deftypefn Supplemental void* memmem (const void *@var{haystack}, @
749 size_t @var{haystack_len} const void *@var{needle}, size_t @var{needle_len})
5fbd9447
ILT
750
751Returns a pointer to the first occurrence of @var{needle} (length
752@var{needle_len}) in @var{haystack} (length @var{haystack_len}).
753Returns @code{NULL} if not found.
754
755@end deftypefn
756
aaa5f039 757@c memmove.c:6
996c0cb0
RW
758@deftypefn Supplemental void* memmove (void *@var{from}, const void *@var{to}, @
759 size_t @var{count})
aaa5f039
DD
760
761Copies @var{count} bytes from memory area @var{from} to memory area
762@var{to}, returning a pointer to @var{to}.
763
764@end deftypefn
765
029bcc09 766@c mempcpy.c:23
996c0cb0
RW
767@deftypefn Supplemental void* mempcpy (void *@var{out}, const void *@var{in}, @
768 size_t @var{length})
029bcc09
KG
769
770Copies @var{length} bytes from memory region @var{in} to region
771@var{out}. Returns a pointer to @var{out} + @var{length}.
772
773@end deftypefn
774
aaa5f039 775@c memset.c:6
996c0cb0
RW
776@deftypefn Supplemental void* memset (void *@var{s}, int @var{c}, @
777 size_t @var{count})
aaa5f039
DD
778
779Sets the first @var{count} bytes of @var{s} to the constant byte
780@var{c}, returning a pointer to @var{s}.
781
782@end deftypefn
783
7cf4c53d 784@c mkstemps.c:58
83fbfe42 785@deftypefn Replacement int mkstemps (char *@var{pattern}, int @var{suffix_len})
aac04c15 786
83fbfe42
GK
787Generate a unique temporary file name from @var{pattern}.
788@var{pattern} has the form:
aac04c15
DD
789
790@example
5bed56d9 791 @var{path}/ccXXXXXX@var{suffix}
aac04c15
DD
792@end example
793
5bed56d9 794@var{suffix_len} tells us how long @var{suffix} is (it can be zero
83fbfe42 795length). The last six characters of @var{pattern} before @var{suffix}
5bed56d9 796must be @samp{XXXXXX}; they are replaced with a string that makes the
aac04c15
DD
797filename unique. Returns a file descriptor open on the file for
798reading and writing.
799
800@end deftypefn
801
996c0cb0 802@c pexecute.txh:278
a584cf65 803@deftypefn Extension void pex_free (struct pex_obj @var{obj})
aac04c15 804
70b1e376
RW
805Clean up and free all data associated with @var{obj}. If you have not
806yet called @code{pex_get_times} or @code{pex_get_status}, this will
807try to kill the subprocesses.
aac04c15 808
a584cf65 809@end deftypefn
aac04c15 810
996c0cb0
RW
811@c pexecute.txh:251
812@deftypefn Extension int pex_get_status (struct pex_obj *@var{obj}, @
813 int @var{count}, int *@var{vector})
aac04c15 814
a584cf65
ILT
815Returns the exit status of all programs run using @var{obj}.
816@var{count} is the number of results expected. The results will be
817placed into @var{vector}. The results are in the order of the calls
818to @code{pex_run}. Returns 0 on error, 1 on success.
aac04c15 819
a584cf65 820@end deftypefn
aac04c15 821
996c0cb0
RW
822@c pexecute.txh:261
823@deftypefn Extension int pex_get_times (struct pex_obj *@var{obj}, @
824 int @var{count}, struct pex_time *@var{vector})
aac04c15 825
a584cf65
ILT
826Returns the process execution times of all programs run using
827@var{obj}. @var{count} is the number of results expected. The
828results will be placed into @var{vector}. The results are in the
829order of the calls to @code{pex_run}. Returns 0 on error, 1 on
830success.
aac04c15 831
e15bb31b
AJ
832@code{struct pex_time} has the following fields of the type
833@code{unsigned long}: @code{user_seconds},
a584cf65
ILT
834@code{user_microseconds}, @code{system_seconds},
835@code{system_microseconds}. On systems which do not support reporting
836process times, all the fields will be set to @code{0}.
aac04c15
DD
837
838@end deftypefn
839
8eff378c 840@c pexecute.txh:2
996c0cb0
RW
841@deftypefn Extension {struct pex_obj *} pex_init (int @var{flags}, @
842 const char *@var{pname}, const char *@var{tempbase})
e15bb31b
AJ
843
844Prepare to execute one or more programs, with standard output of each
845program fed to standard input of the next. This is a system
846independent interface to execute a pipeline.
847
848@var{flags} is a bitwise combination of the following:
849
850@table @code
851
852@vindex PEX_RECORD_TIMES
853@item PEX_RECORD_TIMES
854Record subprocess times if possible.
855
856@vindex PEX_USE_PIPES
857@item PEX_USE_PIPES
858Use pipes for communication between processes, if possible.
859
860@vindex PEX_SAVE_TEMPS
861@item PEX_SAVE_TEMPS
862Don't delete temporary files used for communication between
863processes.
864
865@end table
866
867@var{pname} is the name of program to be executed, used in error
868messages. @var{tempbase} is a base name to use for any required
869temporary files; it may be @code{NULL} to use a randomly chosen name.
870
871@end deftypefn
872
996c0cb0
RW
873@c pexecute.txh:161
874@deftypefn Extension {FILE *} pex_input_file (struct pex_obj *@var{obj}, @
875 int @var{flags}, const char *@var{in_name})
8eff378c
JB
876
877Return a stream for a temporary file to pass to the first program in
878the pipeline as input.
879
880The name of the input file is chosen according to the same rules
881@code{pex_run} uses to choose output file names, based on
882@var{in_name}, @var{obj} and the @code{PEX_SUFFIX} bit in @var{flags}.
883
884Don't call @code{fclose} on the returned stream; the first call to
885@code{pex_run} closes it automatically.
886
887If @var{flags} includes @code{PEX_BINARY_OUTPUT}, open the stream in
888binary mode; otherwise, open it in the default mode. Including
889@code{PEX_BINARY_OUTPUT} in @var{flags} has no effect on Unix.
890@end deftypefn
891
996c0cb0
RW
892@c pexecute.txh:179
893@deftypefn Extension {FILE *} pex_input_pipe (struct pex_obj *@var{obj}, @
894 int @var{binary})
8eff378c
JB
895
896Return a stream @var{fp} for a pipe connected to the standard input of
897the first program in the pipeline; @var{fp} is opened for writing.
898You must have passed @code{PEX_USE_PIPES} to the @code{pex_init} call
899that returned @var{obj}.
900
901You must close @var{fp} using @code{fclose} yourself when you have
902finished writing data to the pipeline.
903
904The file descriptor underlying @var{fp} is marked not to be inherited
905by child processes.
906
907On systems that do not support pipes, this function returns
908@code{NULL}, and sets @code{errno} to @code{EINVAL}. If you would
909like to write code that is portable to all systems the @code{pex}
910functions support, consider using @code{pex_input_file} instead.
911
912There are two opportunities for deadlock using
913@code{pex_input_pipe}:
914
915@itemize @bullet
916@item
917Most systems' pipes can buffer only a fixed amount of data; a process
918that writes to a full pipe blocks. Thus, if you write to @file{fp}
919before starting the first process, you run the risk of blocking when
920there is no child process yet to read the data and allow you to
921continue. @code{pex_input_pipe} makes no promises about the
922size of the pipe's buffer, so if you need to write any data at all
923before starting the first process in the pipeline, consider using
924@code{pex_input_file} instead.
925
926@item
927Using @code{pex_input_pipe} and @code{pex_read_output} together
928may also cause deadlock. If the output pipe fills up, so that each
929program in the pipeline is waiting for the next to read more data, and
930you fill the input pipe by writing more data to @var{fp}, then there
931is no way to make progress: the only process that could read data from
932the output pipe is you, but you are blocked on the input pipe.
933
934@end itemize
935
936@end deftypefn
937
996c0cb0
RW
938@c pexecute.txh:286
939@deftypefn Extension {const char *} pex_one (int @var{flags}, @
940 const char *@var{executable}, char * const *@var{argv}, @
941 const char *@var{pname}, const char *@var{outname}, const char *@var{errname}, @
942 int *@var{status}, int *@var{err})
e15bb31b
AJ
943
944An interface to permit the easy execution of a
945single program. The return value and most of the parameters are as
946for a call to @code{pex_run}. @var{flags} is restricted to a
947combination of @code{PEX_SEARCH}, @code{PEX_STDERR_TO_STDOUT}, and
948@code{PEX_BINARY_OUTPUT}. @var{outname} is interpreted as if
949@code{PEX_LAST} were set. On a successful return, @code{*@var{status}} will
950be set to the exit status of the program.
951
952@end deftypefn
953
996c0cb0
RW
954@c pexecute.txh:237
955@deftypefn Extension {FILE *} pex_read_err (struct pex_obj *@var{obj}, @
956 int @var{binary})
7cf4c53d
VP
957
958Returns a @code{FILE} pointer which may be used to read the standard
959error of the last program in the pipeline. When this is used,
960@code{PEX_LAST} should not be used in a call to @code{pex_run}. After
961this is called, @code{pex_run} may no longer be called with the same
962@var{obj}. @var{binary} should be non-zero if the file should be
963opened in binary mode. Don't call @code{fclose} on the returned file;
964it will be closed by @code{pex_free}.
965
966@end deftypefn
967
996c0cb0
RW
968@c pexecute.txh:224
969@deftypefn Extension {FILE *} pex_read_output (struct pex_obj *@var{obj}, @
970 int @var{binary})
a584cf65
ILT
971
972Returns a @code{FILE} pointer which may be used to read the standard
973output of the last program in the pipeline. When this is used,
974@code{PEX_LAST} should not be used in a call to @code{pex_run}. After
975this is called, @code{pex_run} may no longer be called with the same
976@var{obj}. @var{binary} should be non-zero if the file should be
977opened in binary mode. Don't call @code{fclose} on the returned file;
978it will be closed by @code{pex_free}.
979
980@end deftypefn
981
996c0cb0
RW
982@c pexecute.txh:34
983@deftypefn Extension {const char *} pex_run (struct pex_obj *@var{obj}, @
984 int @var{flags}, const char *@var{executable}, char * const *@var{argv}, @
985 const char *@var{outname}, const char *@var{errname}, int *@var{err})
e15bb31b
AJ
986
987Execute one program in a pipeline. On success this returns
988@code{NULL}. On failure it returns an error message, a statically
989allocated string.
990
991@var{obj} is returned by a previous call to @code{pex_init}.
992
993@var{flags} is a bitwise combination of the following:
994
995@table @code
996
997@vindex PEX_LAST
998@item PEX_LAST
999This must be set on the last program in the pipeline. In particular,
1000it should be set when executing a single program. The standard output
1001of the program will be sent to @var{outname}, or, if @var{outname} is
1002@code{NULL}, to the standard output of the calling program. Do @emph{not}
1003set this bit if you want to call @code{pex_read_output}
1004(described below). After a call to @code{pex_run} with this bit set,
1005@var{pex_run} may no longer be called with the same @var{obj}.
1006
1007@vindex PEX_SEARCH
1008@item PEX_SEARCH
1009Search for the program using the user's executable search path.
1010
1011@vindex PEX_SUFFIX
1012@item PEX_SUFFIX
1013@var{outname} is a suffix. See the description of @var{outname},
1014below.
1015
1016@vindex PEX_STDERR_TO_STDOUT
1017@item PEX_STDERR_TO_STDOUT
1018Send the program's standard error to standard output, if possible.
1019
1020@vindex PEX_BINARY_INPUT
1021@vindex PEX_BINARY_OUTPUT
7cf4c53d 1022@vindex PEX_BINARY_ERROR
e15bb31b
AJ
1023@item PEX_BINARY_INPUT
1024@itemx PEX_BINARY_OUTPUT
7cf4c53d
VP
1025@itemx PEX_BINARY_ERROR
1026The standard input (output or error) of the program should be read (written) in
e15bb31b
AJ
1027binary mode rather than text mode. These flags are ignored on systems
1028which do not distinguish binary mode and text mode, such as Unix. For
1029proper behavior these flags should match appropriately---a call to
1030@code{pex_run} using @code{PEX_BINARY_OUTPUT} should be followed by a
1031call using @code{PEX_BINARY_INPUT}.
7cf4c53d
VP
1032
1033@vindex PEX_STDERR_TO_PIPE
1034@item PEX_STDERR_TO_PIPE
1035Send the program's standard error to a pipe, if possible. This flag
1036cannot be specified together with @code{PEX_STDERR_TO_STDOUT}. This
1037flag can be specified only on the last program in pipeline.
1038
e15bb31b
AJ
1039@end table
1040
1041@var{executable} is the program to execute. @var{argv} is the set of
1042arguments to pass to the program; normally @code{@var{argv}[0]} will
1043be a copy of @var{executable}.
1044
1045@var{outname} is used to set the name of the file to use for standard
1046output. There are two cases in which no output file will be used:
1047
1048@enumerate
1049@item
1050if @code{PEX_LAST} is not set in @var{flags}, and @code{PEX_USE_PIPES}
1051was set in the call to @code{pex_init}, and the system supports pipes
1052
1053@item
1054if @code{PEX_LAST} is set in @var{flags}, and @var{outname} is
1055@code{NULL}
1056@end enumerate
1057
1058@noindent
1059Otherwise the code will use a file to hold standard
1060output. If @code{PEX_LAST} is not set, this file is considered to be
1061a temporary file, and it will be removed when no longer needed, unless
1062@code{PEX_SAVE_TEMPS} was set in the call to @code{pex_init}.
1063
1064There are two cases to consider when setting the name of the file to
1065hold standard output.
1066
1067@enumerate
1068@item
1069@code{PEX_SUFFIX} is set in @var{flags}. In this case
1070@var{outname} may not be @code{NULL}. If the @var{tempbase} parameter
1071to @code{pex_init} was not @code{NULL}, then the output file name is
1072the concatenation of @var{tempbase} and @var{outname}. If
1073@var{tempbase} was @code{NULL}, then the output file name is a random
1074file name ending in @var{outname}.
1075
1076@item
1077@code{PEX_SUFFIX} was not set in @var{flags}. In this
1078case, if @var{outname} is not @code{NULL}, it is used as the output
1079file name. If @var{outname} is @code{NULL}, and @var{tempbase} was
1080not NULL, the output file name is randomly chosen using
1081@var{tempbase}. Otherwise the output file name is chosen completely
1082at random.
1083@end enumerate
1084
1085@var{errname} is the file name to use for standard error output. If
1086it is @code{NULL}, standard error is the same as the caller's.
1087Otherwise, standard error is written to the named file.
1088
1089On an error return, the code sets @code{*@var{err}} to an @code{errno}
1090value, or to 0 if there is no relevant @code{errno}.
1091
1092@end deftypefn
1093
996c0cb0
RW
1094@c pexecute.txh:145
1095@deftypefn Extension {const char *} pex_run_in_environment (struct pex_obj *@var{obj}, @
1096 int @var{flags}, const char *@var{executable}, char * const *@var{argv}, @
1097 char * const *@var{env}, int @var{env_size}, const char *@var{outname}, @
1098 const char *@var{errname}, int *@var{err})
ea60341e
MS
1099
1100Execute one program in a pipeline, permitting the environment for the
1101program to be specified. Behaviour and parameters not listed below are
1102as for @code{pex_run}.
1103
1104@var{env} is the environment for the child process, specified as an array of
1105character pointers. Each element of the array should point to a string of the
1106form @code{VAR=VALUE}, with the exception of the last element that must be
1107@code{NULL}.
1108
1109@end deftypefn
1110
996c0cb0
RW
1111@c pexecute.txh:301
1112@deftypefn Extension int pexecute (const char *@var{program}, @
1113 char * const *@var{argv}, const char *@var{this_pname}, @
1114 const char *@var{temp_base}, char **@var{errmsg_fmt}, @
1115 char **@var{errmsg_arg}, int @var{flags})
a584cf65
ILT
1116
1117This is the old interface to execute one or more programs. It is
1118still supported for compatibility purposes, but is no longer
1119documented.
1120
1121@end deftypefn
1122
70b1e376 1123@c strsignal.c:541
ae452ed1 1124@deftypefn Supplemental void psignal (int @var{signo}, char *@var{message})
aac04c15
DD
1125
1126Print @var{message} to the standard error, followed by a colon,
1127followed by the description of the signal specified by @var{signo},
1128followed by a newline.
1129
1130@end deftypefn
1131
aaa5f039
DD
1132@c putenv.c:21
1133@deftypefn Supplemental int putenv (const char *@var{string})
1134
1135Uses @code{setenv} or @code{unsetenv} to put @var{string} into
1136the environment or remove it. If @var{string} is of the form
7f8fa05d 1137@samp{name=value} the string is added; if no @samp{=} is present the
aaa5f039
DD
1138name is unset/removed.
1139
1140@end deftypefn
1141
996c0cb0 1142@c pexecute.txh:312
aac04c15
DD
1143@deftypefn Extension int pwait (int @var{pid}, int *@var{status}, int @var{flags})
1144
a584cf65 1145Another part of the old execution interface.
aac04c15
DD
1146
1147@end deftypefn
1148
1149@c random.c:39
5bed56d9 1150@deftypefn Supplement {long int} random (void)
aac04c15 1151@deftypefnx Supplement void srandom (unsigned int @var{seed})
996c0cb0
RW
1152@deftypefnx Supplement void* initstate (unsigned int @var{seed}, @
1153 void *@var{arg_state}, unsigned long @var{n})
aac04c15
DD
1154@deftypefnx Supplement void* setstate (void *@var{arg_state})
1155
1156Random number functions. @code{random} returns a random number in the
5bed56d9 1157range 0 to @code{LONG_MAX}. @code{srandom} initializes the random
aac04c15
DD
1158number generator to some starting point determined by @var{seed}
1159(else, the values returned by @code{random} are always the same for each
5bed56d9 1160run of the program). @code{initstate} and @code{setstate} allow fine-grained
aac04c15
DD
1161control over the state of the random number generator.
1162
1163@end deftypefn
1164
e39423c0 1165@c concat.c:160
996c0cb0
RW
1166@deftypefn Extension char* reconcat (char *@var{optr}, const char *@var{s1}, @
1167 @dots{}, @code{NULL})
aac04c15
DD
1168
1169Same as @code{concat}, except that if @var{optr} is not @code{NULL} it
1170is freed after the string is created. This is intended to be useful
1171when you're extending an existing string or building up a string in a
1172loop:
1173
1174@example
1175 str = reconcat (str, "pre-", str, NULL);
1176@end example
1177
1178@end deftypefn
1179
aaa5f039
DD
1180@c rename.c:6
1181@deftypefn Supplemental int rename (const char *@var{old}, const char *@var{new})
1182
1183Renames a file from @var{old} to @var{new}. If @var{new} already
1184exists, it is removed.
1185
1186@end deftypefn
1187
1188@c rindex.c:5
1189@deftypefn Supplemental char* rindex (const char *@var{s}, int @var{c})
1190
e922f978 1191Returns a pointer to the last occurrence of the character @var{c} in
7f8fa05d 1192the string @var{s}, or @code{NULL} if not found. The use of @code{rindex} is
aaa5f039
DD
1193deprecated in new programs in favor of @code{strrchr}.
1194
1195@end deftypefn
1196
996c0cb0
RW
1197@c setenv.c:23
1198@deftypefn Supplemental int setenv (const char *@var{name}, @
1199 const char *@var{value}, int @var{overwrite})
aaa5f039
DD
1200@deftypefnx Supplemental void unsetenv (const char *@var{name})
1201
1202@code{setenv} adds @var{name} to the environment with value
1203@var{value}. If the name was already present in the environment,
0e4e9e8f 1204the new value will be stored only if @var{overwrite} is nonzero.
aaa5f039
DD
1205The companion @code{unsetenv} function removes @var{name} from the
1206environment. This implementation is not safe for multithreaded code.
1207
1208@end deftypefn
1209
996c0cb0
RW
1210@c setproctitle.c:31
1211@deftypefn Supplemental void setproctitle (const char *@var{fmt}, ...)
6e9bd0f8
AK
1212
1213Set the title of a process to @var{fmt}. va args not supported for now,
1214but defined for compatibility with BSD.
1215
1216@end deftypefn
1217
a584cf65 1218@c strsignal.c:348
5bed56d9 1219@deftypefn Extension int signo_max (void)
aac04c15
DD
1220
1221Returns the maximum signal value for which a corresponding symbolic
1222name or message is available. Note that in the case where we use the
1223@code{sys_siglist} supplied by the system, it is possible for there to
1224be more symbolic names than messages, or vice versa. In fact, the
1225manual page for @code{psignal(3b)} explicitly warns that one should
1226check the size of the table (@code{NSIG}) before indexing it, since
1227new signal codes may be added to the system before they are added to
1228the table. Thus @code{NSIG} might be smaller than value implied by
1229the largest signo value defined in @code{<signal.h>}.
1230
1231We return the maximum value that can be used to obtain a meaningful
1232symbolic name or message.
1233
1234@end deftypefn
1235
aaa5f039
DD
1236@c sigsetmask.c:8
1237@deftypefn Supplemental int sigsetmask (int @var{set})
1238
1239Sets the signal mask to the one provided in @var{set} and returns
1240the old mask (which, for libiberty's implementation, will always
1241be the value @code{1}).
1242
1243@end deftypefn
1244
996c0cb0
RW
1245@c simple-object.txh:96
1246@deftypefn Extension {const char *} simple_object_attributes_compare @
1247 (simple_object_attributes *@var{attrs1}, simple_object_attributes *@var{attrs2}, @
1248 int *@var{err})
1cfabf34
ILT
1249
1250Compare @var{attrs1} and @var{attrs2}. If they could be linked
1251together without error, return @code{NULL}. Otherwise, return an
1252error message and set @code{*@var{err}} to an errno value or @code{0}
1253if there is no relevant errno.
1254
1255@end deftypefn
1256
996c0cb0
RW
1257@c simple-object.txh:81
1258@deftypefn Extension {simple_object_attributes *} simple_object_fetch_attributes @
1259 (simple_object_read *@var{simple_object}, const char **@var{errmsg}, int *@var{err})
1cfabf34
ILT
1260
1261Fetch the attributes of @var{simple_object}. The attributes are
1262internal information such as the format of the object file, or the
1263architecture it was compiled for. This information will persist until
1264@code{simple_object_attributes_release} is called, even if
1265@var{simple_object} itself is released.
1266
1267On error this returns @code{NULL}, sets @code{*@var{errmsg}} to an
1268error message, and sets @code{*@var{err}} to an errno value or
1269@code{0} if there is no relevant errno.
1270
1271@end deftypefn
1272
996c0cb0
RW
1273@c simple-object.txh:49
1274@deftypefn Extension {int} simple_object_find_section @
1275 (simple_object_read *@var{simple_object} off_t *@var{offset}, @
1276 off_t *@var{length}, const char **@var{errmsg}, int *@var{err})
1cfabf34
ILT
1277
1278Look for the section @var{name} in @var{simple_object}. This returns
1279information for the first section with that name.
1280
1281If found, return 1 and set @code{*@var{offset}} to the offset in the
1282file of the section contents and set @code{*@var{length}} to the
1283length of the section contents. The value in @code{*@var{offset}}
1284will be relative to the offset passed to
1285@code{simple_object_open_read}.
1286
1287If the section is not found, and no error occurs,
1288@code{simple_object_find_section} returns @code{0} and set
1289@code{*@var{errmsg}} to @code{NULL}.
1290
1291If an error occurs, @code{simple_object_find_section} returns
1292@code{0}, sets @code{*@var{errmsg}} to an error message, and sets
1293@code{*@var{err}} to an errno value or @code{0} if there is no
1294relevant errno.
1295
1296@end deftypefn
1297
996c0cb0
RW
1298@c simple-object.txh:27
1299@deftypefn Extension {const char *} simple_object_find_sections @
1300 (simple_object_read *@var{simple_object}, int (*@var{pfn}) (void *@var{data}, @
1301 const char *@var{name}, off_t @var{offset}, off_t @var{length}), @
1302 void *@var{data}, int *@var{err})
1cfabf34
ILT
1303
1304This function calls @var{pfn} for each section in @var{simple_object}.
1305It calls @var{pfn} with the section name, the offset within the file
1306of the section contents, and the length of the section contents. The
1307offset within the file is relative to the offset passed to
1308@code{simple_object_open_read}. The @var{data} argument to this
1309function is passed along to @var{pfn}.
1310
1311If @var{pfn} returns @code{0}, the loop over the sections stops and
1312@code{simple_object_find_sections} returns. If @var{pfn} returns some
1313other value, the loop continues.
1314
1315On success @code{simple_object_find_sections} returns. On error it
1316returns an error string, and sets @code{*@var{err}} to an errno value
1317or @code{0} if there is no relevant errno.
1318
1319@end deftypefn
1320
1321@c simple-object.txh:2
996c0cb0
RW
1322@deftypefn Extension {simple_object_read *} simple_object_open_read @
1323 (int @var{descriptor}, off_t @var{offset}, const char *{segment_name}, @
1324 const char **@var{errmsg}, int *@var{err})
1cfabf34
ILT
1325
1326Opens an object file for reading. Creates and returns an
1327@code{simple_object_read} pointer which may be passed to other
1328functions to extract data from the object file.
1329
1330@var{descriptor} holds a file descriptor which permits reading.
1331
1332@var{offset} is the offset into the file; this will be @code{0} in the
1333normal case, but may be a different value when reading an object file
1334in an archive file.
1335
1336@var{segment_name} is only used with the Mach-O file format used on
1337Darwin aka Mac OS X. It is required on that platform, and means to
1338only look at sections within the segment with that name. The
1339parameter is ignored on other systems.
1340
1341If an error occurs, this functions returns @code{NULL} and sets
1342@code{*@var{errmsg}} to an error string and sets @code{*@var{err}} to
1343an errno value or @code{0} if there is no relevant errno.
1344
1345@end deftypefn
1346
996c0cb0
RW
1347@c simple-object.txh:107
1348@deftypefn Extension {void} simple_object_release_attributes @
1349 (simple_object_attributes *@var{attrs})
1cfabf34
ILT
1350
1351Release all resources associated with @var{attrs}.
1352
1353@end deftypefn
1354
996c0cb0
RW
1355@c simple-object.txh:73
1356@deftypefn Extension {void} simple_object_release_read @
1357 (simple_object_read *@var{simple_object})
1cfabf34
ILT
1358
1359Release all resources associated with @var{simple_object}. This does
1360not close the file descriptor.
1361
1362@end deftypefn
1363
996c0cb0
RW
1364@c simple-object.txh:184
1365@deftypefn Extension {void} simple_object_release_write @
1366 (simple_object_write *@var{simple_object})
1cfabf34
ILT
1367
1368Release all resources associated with @var{simple_object}.
1369
1370@end deftypefn
1371
996c0cb0
RW
1372@c simple-object.txh:114
1373@deftypefn Extension {simple_object_write *} simple_object_start_write @
1374 (simple_object_attributes @var{attrs}, const char *@var{segment_name}, @
1375 const char **@var{errmsg}, int *@var{err})
1cfabf34
ILT
1376
1377Start creating a new object file using the object file format
1378described in @var{attrs}. You must fetch attribute information from
1379an existing object file before you can create a new one. There is
1380currently no support for creating an object file de novo.
1381
1382@var{segment_name} is only used with Mach-O as found on Darwin aka Mac
1383OS X. The parameter is required on that target. It means that all
1384sections are created within the named segment. It is ignored for
1385other object file formats.
1386
1387On error @code{simple_object_start_write} returns @code{NULL}, sets
1388@code{*@var{ERRMSG}} to an error message, and sets @code{*@var{err}}
1389to an errno value or @code{0} if there is no relevant errno.
1390
1391@end deftypefn
1392
996c0cb0
RW
1393@c simple-object.txh:153
1394@deftypefn Extension {const char *} simple_object_write_add_data @
1395 (simple_object_write *@var{simple_object}, @
1396 simple_object_write_section *@var{section}, const void *@var{buffer}, @
1397 size_t @var{size}, int @var{copy}, int *@var{err})
1cfabf34
ILT
1398
1399Add data @var{buffer}/@var{size} to @var{section} in
1400@var{simple_object}. If @var{copy} is non-zero, the data will be
1401copied into memory if necessary. If @var{copy} is zero, @var{buffer}
1402must persist until @code{simple_object_write_to_file} is called. is
1403released.
1404
1405On success this returns @code{NULL}. On error this returns an error
1406message, and sets @code{*@var{err}} to an errno value or 0 if there is
1407no relevant erro.
1408
1409@end deftypefn
1410
996c0cb0
RW
1411@c simple-object.txh:134
1412@deftypefn Extension {simple_object_write_section *} simple_object_write_create_section @
1413 (simple_object_write *@var{simple_object}, const char *@var{name}, @
1414 unsigned int @var{align}, const char **@var{errmsg}, int *@var{err})
1cfabf34
ILT
1415
1416Add a section to @var{simple_object}. @var{name} is the name of the
1417new section. @var{align} is the required alignment expressed as the
1418number of required low-order 0 bits (e.g., 2 for alignment to a 32-bit
1419boundary).
1420
1421The section is created as containing data, readable, not writable, not
1422executable, not loaded at runtime. The section is not written to the
1423file until @code{simple_object_write_to_file} is called.
1424
1425On error this returns @code{NULL}, sets @code{*@var{errmsg}} to an
1426error message, and sets @code{*@var{err}} to an errno value or
1427@code{0} if there is no relevant errno.
1428
1429@end deftypefn
1430
996c0cb0
RW
1431@c simple-object.txh:170
1432@deftypefn Extension {const char *} simple_object_write_to_file @
1433 (simple_object_write *@var{simple_object}, int @var{descriptor}, int *@var{err})
1cfabf34
ILT
1434
1435Write the complete object file to @var{descriptor}, an open file
1436descriptor. This writes out all the data accumulated by calls to
1437@code{simple_object_write_create_section} and
1438@var{simple_object_write_add_data}.
1439
1440This returns @code{NULL} on success. On error this returns an error
1441message and sets @code{*@var{err}} to an errno value or @code{0} if
1442there is no relevant errno.
1443
1444@end deftypefn
1445
bd3fbc6b 1446@c snprintf.c:28
996c0cb0
RW
1447@deftypefn Supplemental int snprintf (char *@var{buf}, size_t @var{n}, @
1448 const char *@var{format}, ...)
bd3fbc6b 1449
b524249c
ILT
1450This function is similar to @code{sprintf}, but it will write to
1451@var{buf} at most @code{@var{n}-1} bytes of text, followed by a
1452terminating null byte, for a total of @var{n} bytes.
1453On error the return value is -1, otherwise it returns the number of
1454bytes, not including the terminating null byte, that would have been
1455written had @var{n} been sufficiently large, regardless of the actual
1456value of @var{n}. Note some pre-C99 system libraries do not implement
1457this correctly so users cannot generally rely on the return value if
1458the system version of this function is used.
bd3fbc6b
KG
1459
1460@end deftypefn
1461
aac04c15
DD
1462@c spaces.c:22
1463@deftypefn Extension char* spaces (int @var{count})
1464
1465Returns a pointer to a memory region filled with the specified
1466number of spaces and null terminated. The returned pointer is
1467valid until at least the next call.
1468
1469@end deftypefn
1470
996c0cb0
RW
1471@c splay-tree.c:303
1472@deftypefn Supplemental splay_tree splay_tree_new_with_typed_alloc @
1473(splay_tree_compare_fn @var{compare_fn}, @
1474splay_tree_delete_key_fn @var{delete_key_fn}, @
1475splay_tree_delete_value_fn @var{delete_value_fn}, @
1476splay_tree_allocate_fn @var{tree_allocate_fn}, @
1477splay_tree_allocate_fn @var{node_allocate_fn}, @
1478splay_tree_deallocate_fn @var{deallocate_fn}, @
1479void * @var{allocate_data})
1480
1481This function creates a splay tree that uses two different allocators
1482@var{tree_allocate_fn} and @var{node_allocate_fn} to use for allocating the
1483tree itself and its nodes respectively. This is useful when variables of
1484different types need to be allocated with different allocators.
1485
1486The splay tree will use @var{compare_fn} to compare nodes,
1487@var{delete_key_fn} to deallocate keys, and @var{delete_value_fn} to
1488deallocate values.
1489
1490@end deftypefn
1491
9a9baa52
ILT
1492@c stack-limit.c:28
1493@deftypefn Extension void stack_limit_increase (unsigned long @var{pref})
1494
1495Attempt to increase stack size limit to @var{pref} bytes if possible.
1496
1497@end deftypefn
1498
029bcc09
KG
1499@c stpcpy.c:23
1500@deftypefn Supplemental char* stpcpy (char *@var{dst}, const char *@var{src})
1501
1502Copies the string @var{src} into @var{dst}. Returns a pointer to
1503@var{dst} + strlen(@var{src}).
1504
1505@end deftypefn
1506
1507@c stpncpy.c:23
996c0cb0
RW
1508@deftypefn Supplemental char* stpncpy (char *@var{dst}, const char *@var{src}, @
1509 size_t @var{len})
029bcc09
KG
1510
1511Copies the string @var{src} into @var{dst}, copying exactly @var{len}
1512and padding with zeros if necessary. If @var{len} < strlen(@var{src})
1513then return @var{dst} + @var{len}, otherwise returns @var{dst} +
1514strlen(@var{src}).
1515
1516@end deftypefn
1517
aaa5f039
DD
1518@c strcasecmp.c:15
1519@deftypefn Supplemental int strcasecmp (const char *@var{s1}, const char *@var{s2})
1520
1521A case-insensitive @code{strcmp}.
1522
1523@end deftypefn
1524
1525@c strchr.c:6
1526@deftypefn Supplemental char* strchr (const char *@var{s}, int @var{c})
1527
e922f978 1528Returns a pointer to the first occurrence of the character @var{c} in
7f8fa05d 1529the string @var{s}, or @code{NULL} if not found. If @var{c} is itself the
aaa5f039
DD
1530null character, the results are undefined.
1531
1532@end deftypefn
1533
1534@c strdup.c:3
1535@deftypefn Supplemental char* strdup (const char *@var{s})
1536
1537Returns a pointer to a copy of @var{s} in memory obtained from
7f8fa05d 1538@code{malloc}, or @code{NULL} if insufficient memory was available.
aaa5f039
DD
1539
1540@end deftypefn
1541
a584cf65 1542@c strerror.c:670
aac04c15 1543@deftypefn Replacement {const char*} strerrno (int @var{errnum})
aaa5f039
DD
1544
1545Given an error number returned from a system call (typically returned
1546in @code{errno}), returns a pointer to a string containing the
7f8fa05d 1547symbolic name of that error number, as found in @code{<errno.h>}.
aaa5f039
DD
1548
1549If the supplied error number is within the valid range of indices for
1550symbolic names, but no name is available for the particular error
aac04c15 1551number, then returns the string @samp{Error @var{num}}, where @var{num}
e922f978 1552is the error number.
aaa5f039
DD
1553
1554If the supplied error number is not within the range of valid
7f8fa05d 1555indices, then returns @code{NULL}.
aaa5f039
DD
1556
1557The contents of the location pointed to are only guaranteed to be
e922f978 1558valid until the next call to @code{strerrno}.
aaa5f039
DD
1559
1560@end deftypefn
1561
e8805990 1562@c strerror.c:603
aac04c15 1563@deftypefn Supplemental char* strerror (int @var{errnoval})
aaa5f039
DD
1564
1565Maps an @code{errno} number to an error message string, the contents
1566of which are implementation defined. On systems which have the
1567external variables @code{sys_nerr} and @code{sys_errlist}, these
1568strings will be the same as the ones used by @code{perror}.
1569
1570If the supplied error number is within the valid range of indices for
1571the @code{sys_errlist}, but no message is available for the particular
aac04c15 1572error number, then returns the string @samp{Error @var{num}}, where
e922f978 1573@var{num} is the error number.
aaa5f039
DD
1574
1575If the supplied error number is not a valid index into
7f8fa05d 1576@code{sys_errlist}, returns @code{NULL}.
aaa5f039
DD
1577
1578The returned string is only guaranteed to be valid only until the
1579next call to @code{strerror}.
1580
1581@end deftypefn
1582
1583@c strncasecmp.c:15
1584@deftypefn Supplemental int strncasecmp (const char *@var{s1}, const char *@var{s2})
1585
1586A case-insensitive @code{strncmp}.
1587
1588@end deftypefn
1589
1590@c strncmp.c:6
996c0cb0
RW
1591@deftypefn Supplemental int strncmp (const char *@var{s1}, @
1592 const char *@var{s2}, size_t @var{n})
aaa5f039
DD
1593
1594Compares the first @var{n} bytes of two strings, returning a value as
1595@code{strcmp}.
1596
1597@end deftypefn
1598
17998b22
KG
1599@c strndup.c:23
1600@deftypefn Extension char* strndup (const char *@var{s}, size_t @var{n})
1601
1602Returns a pointer to a copy of @var{s} with at most @var{n} characters
1603in memory obtained from @code{malloc}, or @code{NULL} if insufficient
1604memory was available. The result is always NUL terminated.
1605
1606@end deftypefn
1607
9a9baa52
ILT
1608@c strnlen.c:6
1609@deftypefn Supplemental size_t strnlen (const char *@var{s}, size_t @var{maxlen})
1610
1611Returns the length of @var{s}, as with @code{strlen}, but never looks
1612past the first @var{maxlen} characters in the string. If there is no
1613'\0' character in the first @var{maxlen} characters, returns
1614@var{maxlen}.
1615
1616@end deftypefn
1617
aaa5f039
DD
1618@c strrchr.c:6
1619@deftypefn Supplemental char* strrchr (const char *@var{s}, int @var{c})
1620
e922f978 1621Returns a pointer to the last occurrence of the character @var{c} in
7f8fa05d 1622the string @var{s}, or @code{NULL} if not found. If @var{c} is itself the
aaa5f039
DD
1623null character, the results are undefined.
1624
1625@end deftypefn
1626
a584cf65 1627@c strsignal.c:383
aac04c15
DD
1628@deftypefn Supplemental {const char *} strsignal (int @var{signo})
1629
1630Maps an signal number to an signal message string, the contents of
1631which are implementation defined. On systems which have the external
1632variable @code{sys_siglist}, these strings will be the same as the
1633ones used by @code{psignal()}.
1634
1635If the supplied signal number is within the valid range of indices for
1636the @code{sys_siglist}, but no message is available for the particular
1637signal number, then returns the string @samp{Signal @var{num}}, where
1638@var{num} is the signal number.
1639
1640If the supplied signal number is not a valid index into
1641@code{sys_siglist}, returns @code{NULL}.
1642
1643The returned string is only guaranteed to be valid only until the next
1644call to @code{strsignal}.
1645
1646@end deftypefn
1647
70b1e376 1648@c strsignal.c:448
aac04c15
DD
1649@deftypefn Extension {const char*} strsigno (int @var{signo})
1650
1651Given an signal number, returns a pointer to a string containing the
1652symbolic name of that signal number, as found in @code{<signal.h>}.
1653
1654If the supplied signal number is within the valid range of indices for
1655symbolic names, but no name is available for the particular signal
1656number, then returns the string @samp{Signal @var{num}}, where
1657@var{num} is the signal number.
1658
1659If the supplied signal number is not within the range of valid
1660indices, then returns @code{NULL}.
1661
1662The contents of the location pointed to are only guaranteed to be
1663valid until the next call to @code{strsigno}.
1664
1665@end deftypefn
1666
aaa5f039
DD
1667@c strstr.c:6
1668@deftypefn Supplemental char* strstr (const char *@var{string}, const char *@var{sub})
1669
1670This function searches for the substring @var{sub} in the string
e922f978 1671@var{string}, not including the terminating null characters. A pointer
7f8fa05d 1672to the first occurrence of @var{sub} is returned, or @code{NULL} if the
aaa5f039
DD
1673substring is absent. If @var{sub} points to a string with zero
1674length, the function returns @var{string}.
1675
1676@end deftypefn
1677
1678@c strtod.c:27
996c0cb0
RW
1679@deftypefn Supplemental double strtod (const char *@var{string}, @
1680 char **@var{endptr})
aaa5f039 1681
0e4e9e8f 1682This ISO C function converts the initial portion of @var{string} to a
7f8fa05d 1683@code{double}. If @var{endptr} is not @code{NULL}, a pointer to the
aaa5f039
DD
1684character after the last character used in the conversion is stored in
1685the location referenced by @var{endptr}. If no conversion is
1686performed, zero is returned and the value of @var{string} is stored in
1687the location referenced by @var{endptr}.
1688
1689@end deftypefn
1690
a584cf65 1691@c strerror.c:729
aac04c15 1692@deftypefn Extension int strtoerrno (const char *@var{name})
aaa5f039 1693
7f8fa05d 1694Given the symbolic name of a error number (e.g., @code{EACCES}), map it
aaa5f039
DD
1695to an errno value. If no translation is found, returns 0.
1696
1697@end deftypefn
1698
1699@c strtol.c:33
996c0cb0
RW
1700@deftypefn Supplemental {long int} strtol (const char *@var{string}, @
1701 char **@var{endptr}, int @var{base})
1702@deftypefnx Supplemental {unsigned long int} strtoul (const char *@var{string}, @
1703 char **@var{endptr}, int @var{base})
aaa5f039
DD
1704
1705The @code{strtol} function converts the string in @var{string} to a
1706long integer value according to the given @var{base}, which must be
1707between 2 and 36 inclusive, or be the special value 0. If @var{base}
1708is 0, @code{strtol} will look for the prefixes @code{0} and @code{0x}
1709to indicate bases 8 and 16, respectively, else default to base 10.
1710When the base is 16 (either explicitly or implicitly), a prefix of
e922f978 1711@code{0x} is allowed. The handling of @var{endptr} is as that of
aac04c15
DD
1712@code{strtod} above. The @code{strtoul} function is the same, except
1713that the converted value is unsigned.
1714
1715@end deftypefn
1716
70b1e376 1717@c strsignal.c:502
aac04c15
DD
1718@deftypefn Extension int strtosigno (const char *@var{name})
1719
1720Given the symbolic name of a signal, map it to a signal number. If no
1721translation is found, returns 0.
aaa5f039
DD
1722
1723@end deftypefn
1724
ddbbee51 1725@c strverscmp.c:25
83fbfe42
GK
1726@deftypefun int strverscmp (const char *@var{s1}, const char *@var{s2})
1727The @code{strverscmp} function compares the string @var{s1} against
1728@var{s2}, considering them as holding indices/version numbers. Return
1729value follows the same conventions as found in the @code{strverscmp}
1730function. In fact, if @var{s1} and @var{s2} contain no digits,
1731@code{strverscmp} behaves like @code{strcmp}.
1732
1733Basically, we compare strings normally (character by character), until
1734we find a digit in each string - then we enter a special comparison
1735mode, where each sequence of digits is taken as a whole. If we reach the
1736end of these two parts without noticing a difference, we return to the
1737standard comparison mode. There are two types of numeric parts:
1738"integral" and "fractional" (those begin with a '0'). The types
1739of the numeric parts affect the way we sort them:
1740
1741@itemize @bullet
1742@item
1743integral/integral: we compare values as you would expect.
1744
1745@item
1746fractional/integral: the fractional part is less than the integral one.
1747Again, no surprise.
1748
1749@item
1750fractional/fractional: the things become a bit more complex.
1751If the common prefix contains only leading zeroes, the longest part is less
1752than the other one; else the comparison behaves normally.
1753@end itemize
1754
1755@smallexample
1756strverscmp ("no digit", "no digit")
1757 @result{} 0 // @r{same behavior as strcmp.}
1758strverscmp ("item#99", "item#100")
1759 @result{} <0 // @r{same prefix, but 99 < 100.}
1760strverscmp ("alpha1", "alpha001")
1761 @result{} >0 // @r{fractional part inferior to integral one.}
1762strverscmp ("part1_f012", "part1_f01")
1763 @result{} >0 // @r{two fractional parts.}
1764strverscmp ("foo.009", "foo.0")
1765 @result{} <0 // @r{idem, but with leading zeroes only.}
1766@end smallexample
1767
1768This function is especially useful when dealing with filename sorting,
1769because filenames frequently hold indices/version numbers.
1770@end deftypefun
1771
9a9baa52
ILT
1772@c timeval-utils.c:43
1773@deftypefn Extension void timeval_add (struct timeval *@var{a}, @
1774 struct timeval *@var{b}, struct timeval *@var{result})
1775
1776Adds @var{a} to @var{b} and stores the result in @var{result}.
1777
1778@end deftypefn
1779
1780@c timeval-utils.c:67
1781@deftypefn Extension void timeval_sub (struct timeval *@var{a}, @
1782 struct timeval *@var{b}, struct timeval *@var{result})
1783
1784Subtracts @var{b} from @var{a} and stores the result in @var{result}.
1785
1786@end deftypefn
1787
aaa5f039
DD
1788@c tmpnam.c:3
1789@deftypefn Supplemental char* tmpnam (char *@var{s})
1790
1791This function attempts to create a name for a temporary file, which
1792will be a valid file name yet not exist when @code{tmpnam} checks for
1793it. @var{s} must point to a buffer of at least @code{L_tmpnam} bytes,
7f8fa05d 1794or be @code{NULL}. Use of this function creates a security risk, and it must
aaa5f039
DD
1795not be used in new projects. Use @code{mkstemp} instead.
1796
1797@end deftypefn
1798
17998b22
KG
1799@c unlink-if-ordinary.c:27
1800@deftypefn Supplemental int unlink_if_ordinary (const char*)
1801
1802Unlinks the named file, unless it is special (e.g. a device file).
1803Returns 0 when the file was unlinked, a negative value (and errno set) when
1804there was an error deleting the file, and a positive value if no attempt
1805was made to unlink the file because it is special.
1806
1807@end deftypefn
1808
32e82bd8
KG
1809@c fopen_unlocked.c:31
1810@deftypefn Extension void unlock_std_streams (void)
1811
1812If the OS supports it, ensure that the standard I/O streams,
1813@code{stdin}, @code{stdout} and @code{stderr} are setup to avoid any
1814multi-threaded locking. Otherwise do nothing.
1815
1816@end deftypefn
1817
6feaa084
KG
1818@c fopen_unlocked.c:23
1819@deftypefn Extension void unlock_stream (FILE * @var{stream})
1820
1821If the OS supports it, ensure that the supplied stream is setup to
1822avoid any multi-threaded locking. Otherwise leave the @code{FILE}
1823pointer unchanged. If the @var{stream} is @code{NULL} do nothing.
1824
1825@end deftypefn
1826
a584cf65 1827@c vasprintf.c:47
996c0cb0
RW
1828@deftypefn Extension int vasprintf (char **@var{resptr}, @
1829 const char *@var{format}, va_list @var{args})
aac04c15
DD
1830
1831Like @code{vsprintf}, but instead of passing a pointer to a buffer,
1832you pass a pointer to a pointer. This function will compute the size
1833of the buffer needed, allocate memory with @code{malloc}, and store a
1834pointer to the allocated memory in @code{*@var{resptr}}. The value
1835returned is the same as @code{vsprintf} would return. If memory could
8d398258 1836not be allocated, minus one is returned and @code{NULL} is stored in
aac04c15
DD
1837@code{*@var{resptr}}.
1838
1839@end deftypefn
1840
aaa5f039 1841@c vfork.c:6
7f8fa05d 1842@deftypefn Supplemental int vfork (void)
aaa5f039
DD
1843
1844Emulates @code{vfork} by calling @code{fork} and returning its value.
1845
1846@end deftypefn
1847
1848@c vprintf.c:3
1849@deftypefn Supplemental int vprintf (const char *@var{format}, va_list @var{ap})
996c0cb0
RW
1850@deftypefnx Supplemental int vfprintf (FILE *@var{stream}, @
1851 const char *@var{format}, va_list @var{ap})
1852@deftypefnx Supplemental int vsprintf (char *@var{str}, @
1853 const char *@var{format}, va_list @var{ap})
aaa5f039
DD
1854
1855These functions are the same as @code{printf}, @code{fprintf}, and
1856@code{sprintf}, respectively, except that they are called with a
1857@code{va_list} instead of a variable number of arguments. Note that
1858they do not call @code{va_end}; this is the application's
1859responsibility. In @libib{} they are implemented in terms of the
1860nonstandard but common function @code{_doprnt}.
1861
1862@end deftypefn
1863
bd3fbc6b 1864@c vsnprintf.c:28
996c0cb0
RW
1865@deftypefn Supplemental int vsnprintf (char *@var{buf}, size_t @var{n}, @
1866 const char *@var{format}, va_list @var{ap})
bd3fbc6b 1867
b524249c
ILT
1868This function is similar to @code{vsprintf}, but it will write to
1869@var{buf} at most @code{@var{n}-1} bytes of text, followed by a
1870terminating null byte, for a total of @var{n} bytes. On error the
1871return value is -1, otherwise it returns the number of characters that
1872would have been printed had @var{n} been sufficiently large,
1873regardless of the actual value of @var{n}. Note some pre-C99 system
1874libraries do not implement this correctly so users cannot generally
1875rely on the return value if the system version of this function is
1876used.
bd3fbc6b
KG
1877
1878@end deftypefn
1879
aaa5f039
DD
1880@c waitpid.c:3
1881@deftypefn Supplemental int waitpid (int @var{pid}, int *@var{status}, int)
1882
1883This is a wrapper around the @code{wait} function. Any ``special''
1884values of @var{pid} depend on your implementation of @code{wait}, as
1885does the return value. The third argument is unused in @libib{}.
1886
1887@end deftypefn
1888
9a9baa52 1889@c argv.c:286
f4e00f44
DD
1890@deftypefn Extension int writeargv (const char **@var{argv}, FILE *@var{file})
1891
1892Write each member of ARGV, handling all necessary quoting, to the file
1893named by FILE, separated by whitespace. Return 0 on success, non-zero
1894if an error occurred while writing to FILE.
1895
1896@end deftypefn
1897
aaa5f039
DD
1898@c xatexit.c:11
1899@deftypefun int xatexit (void (*@var{fn}) (void))
1900
1901Behaves as the standard @code{atexit} function, but with no limit on
7f8fa05d 1902the number of registered functions. Returns 0 on success, or @minus{}1 on
aaa5f039
DD
1903failure. If you use @code{xatexit} to register functions, you must use
1904@code{xexit} to terminate your program.
1905
1906@end deftypefun
1907
e922f978 1908@c xmalloc.c:38
7f8fa05d 1909@deftypefn Replacement void* xcalloc (size_t @var{nelem}, size_t @var{elsize})
aaa5f039
DD
1910
1911Allocate memory without fail, and set it to zero. This routine functions
1912like @code{calloc}, but will behave the same as @code{xmalloc} if memory
1913cannot be found.
1914
1915@end deftypefn
1916
1917@c xexit.c:22
1918@deftypefn Replacement void xexit (int @var{code})
1919
1920Terminates the program. If any functions have been registered with
e922f978 1921the @code{xatexit} replacement function, they will be called first.
aaa5f039
DD
1922Termination is handled via the system's normal @code{exit} call.
1923
1924@end deftypefn
1925
1926@c xmalloc.c:22
1927@deftypefn Replacement void* xmalloc (size_t)
1928
1929Allocate memory without fail. If @code{malloc} fails, this will print
e922f978
EZ
1930a message to @code{stderr} (using the name set by
1931@code{xmalloc_set_program_name},
aaa5f039
DD
1932if any) and then call @code{xexit}. Note that it is therefore safe for
1933a program to contain @code{#define malloc xmalloc} in its source.
1934
1935@end deftypefn
1936
e922f978 1937@c xmalloc.c:53
aaa5f039
DD
1938@deftypefn Replacement void xmalloc_failed (size_t)
1939
1940This function is not meant to be called by client code, and is listed
1941here for completeness only. If any of the allocation routines fail, this
1942function will be called to print an error message and terminate execution.
1943
1944@end deftypefn
1945
e922f978 1946@c xmalloc.c:46
aaa5f039
DD
1947@deftypefn Replacement void xmalloc_set_program_name (const char *@var{name})
1948
1949You can use this to set the name of the program used by
1950@code{xmalloc_failed} when printing a failure message.
1951
1952@end deftypefn
1953
1954@c xmemdup.c:7
996c0cb0
RW
1955@deftypefn Replacement void* xmemdup (void *@var{input}, @
1956 size_t @var{copy_size}, size_t @var{alloc_size})
aaa5f039
DD
1957
1958Duplicates a region of memory without fail. First, @var{alloc_size} bytes
1959are allocated, then @var{copy_size} bytes from @var{input} are copied into
1960it, and the new memory is returned. If fewer bytes are copied than were
1961allocated, the remaining memory is zeroed.
1962
1963@end deftypefn
1964
e922f978 1965@c xmalloc.c:32
7f8fa05d 1966@deftypefn Replacement void* xrealloc (void *@var{ptr}, size_t @var{size})
aaa5f039
DD
1967Reallocate memory without fail. This routine functions like @code{realloc},
1968but will behave the same as @code{xmalloc} if memory cannot be found.
1969
1970@end deftypefn
1971
1972@c xstrdup.c:7
1973@deftypefn Replacement char* xstrdup (const char *@var{s})
1974
1975Duplicates a character string without fail, using @code{xmalloc} to
1976obtain memory.
1977
1978@end deftypefn
1979
1980@c xstrerror.c:7
1981@deftypefn Replacement char* xstrerror (int @var{errnum})
1982
1983Behaves exactly like the standard @code{strerror} function, but
7f8fa05d 1984will never return a @code{NULL} pointer.
aaa5f039
DD
1985
1986@end deftypefn
1987
17998b22
KG
1988@c xstrndup.c:23
1989@deftypefn Replacement char* xstrndup (const char *@var{s}, size_t @var{n})
1990
1991Returns a pointer to a copy of @var{s} with at most @var{n} characters
1992without fail, using @code{xmalloc} to obtain memory. The result is
1993always NUL terminated.
1994
1995@end deftypefn
1996
aaa5f039 1997