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