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