xref: /netbsd-src/external/gpl3/binutils.old/dist/libiberty/functions.texi (revision e992f068c547fd6e84b3f104dc2340adcc955732)
116dce513Schristos@c Automatically generated from *.c and others (the comments before
216dce513Schristos@c each entry tell you which file and where in that file).  DO NOT EDIT!
316dce513Schristos@c Edit the *.c files, configure with --enable-maintainer-mode,
416dce513Schristos@c run 'make stamp-functions' and gather-docs will build a new copy.
516dce513Schristos
616dce513Schristos@c alloca.c:26
716dce513Schristos@deftypefn Replacement void* alloca (size_t @var{size})
816dce513Schristos
916dce513SchristosThis function allocates memory which will be automatically reclaimed
1016dce513Schristosafter the procedure exits.  The @libib{} implementation does not free
1116dce513Schristosthe memory immediately but will do so eventually during subsequent
1216dce513Schristoscalls to this function.  Memory is allocated using @code{xmalloc} under
1316dce513Schristosnormal circumstances.
1416dce513Schristos
1516dce513SchristosThe header file @file{alloca-conf.h} can be used in conjunction with the
1616dce513SchristosGNU Autoconf test @code{AC_FUNC_ALLOCA} to test for and properly make
1716dce513Schristosavailable this function.  The @code{AC_FUNC_ALLOCA} test requires that
1816dce513Schristosclient code use a block of preprocessor code to be safe (see the Autoconf
1916dce513Schristosmanual for more); this header incorporates that logic and more, including
2016dce513Schristosthe possibility of a GCC built-in function.
2116dce513Schristos
2216dce513Schristos@end deftypefn
2316dce513Schristos
2416dce513Schristos@c asprintf.c:32
2516dce513Schristos@deftypefn Extension int asprintf (char **@var{resptr}, const char *@var{format}, ...)
2616dce513Schristos
2716dce513SchristosLike @code{sprintf}, but instead of passing a pointer to a buffer, you
2816dce513Schristospass a pointer to a pointer.  This function will compute the size of
2916dce513Schristosthe buffer needed, allocate memory with @code{malloc}, and store a
3016dce513Schristospointer to the allocated memory in @code{*@var{resptr}}.  The value
3116dce513Schristosreturned is the same as @code{sprintf} would return.  If memory could
3216dce513Schristosnot be allocated, minus one is returned and @code{NULL} is stored in
3316dce513Schristos@code{*@var{resptr}}.
3416dce513Schristos
3516dce513Schristos@end deftypefn
3616dce513Schristos
3716dce513Schristos@c atexit.c:6
3816dce513Schristos@deftypefn Supplemental int atexit (void (*@var{f})())
3916dce513Schristos
4016dce513SchristosCauses function @var{f} to be called at exit.  Returns 0.
4116dce513Schristos
4216dce513Schristos@end deftypefn
4316dce513Schristos
4416dce513Schristos@c basename.c:6
4516dce513Schristos@deftypefn Supplemental char* basename (const char *@var{name})
4616dce513Schristos
4716dce513SchristosReturns a pointer to the last component of pathname @var{name}.
4816dce513SchristosBehavior is undefined if the pathname ends in a directory separator.
4916dce513Schristos
5016dce513Schristos@end deftypefn
5116dce513Schristos
5216dce513Schristos@c bcmp.c:6
5316dce513Schristos@deftypefn Supplemental int bcmp (char *@var{x}, char *@var{y}, int @var{count})
5416dce513Schristos
5516dce513SchristosCompares the first @var{count} bytes of two areas of memory.  Returns
5616dce513Schristoszero if they are the same, nonzero otherwise.  Returns zero if
5716dce513Schristos@var{count} is zero.  A nonzero result only indicates a difference,
5816dce513Schristosit does not indicate any sorting order (say, by having a positive
5916dce513Schristosresult mean @var{x} sorts before @var{y}).
6016dce513Schristos
6116dce513Schristos@end deftypefn
6216dce513Schristos
6316dce513Schristos@c bcopy.c:3
6416dce513Schristos@deftypefn Supplemental void bcopy (char *@var{in}, char *@var{out}, int @var{length})
6516dce513Schristos
6616dce513SchristosCopies @var{length} bytes from memory region @var{in} to region
6716dce513Schristos@var{out}.  The use of @code{bcopy} is deprecated in new programs.
6816dce513Schristos
6916dce513Schristos@end deftypefn
7016dce513Schristos
7116dce513Schristos@c bsearch.c:33
7216dce513Schristos@deftypefn Supplemental void* bsearch (const void *@var{key}, @
7316dce513Schristos  const void *@var{base}, size_t @var{nmemb}, size_t @var{size}, @
7416dce513Schristos  int (*@var{compar})(const void *, const void *))
7516dce513Schristos
7616dce513SchristosPerforms a search over an array of @var{nmemb} elements pointed to by
7716dce513Schristos@var{base} for a member that matches the object pointed to by @var{key}.
7816dce513SchristosThe size of each member is specified by @var{size}.  The array contents
7916dce513Schristosshould be sorted in ascending order according to the @var{compar}
8016dce513Schristoscomparison function.  This routine should take two arguments pointing to
8116dce513Schristosthe @var{key} and to an array member, in that order, and should return an
8216dce513Schristosinteger less than, equal to, or greater than zero if the @var{key} object
8316dce513Schristosis respectively less than, matching, or greater than the array member.
8416dce513Schristos
8516dce513Schristos@end deftypefn
8616dce513Schristos
87*e992f068Schristos@c bsearch_r.c:33
88*e992f068Schristos@deftypefn Supplemental void* bsearch_r (const void *@var{key}, @
89*e992f068Schristos  const void *@var{base}, size_t @var{nmemb}, size_t @var{size}, @
90*e992f068Schristos  int (*@var{compar})(const void *, const void *, void *), void *@var{arg})
91*e992f068Schristos
92*e992f068SchristosPerforms a search over an array of @var{nmemb} elements pointed to by
93*e992f068Schristos@var{base} for a member that matches the object pointed to by @var{key}.
94*e992f068SchristosThe size of each member is specified by @var{size}.  The array contents
95*e992f068Schristosshould be sorted in ascending order according to the @var{compar}
96*e992f068Schristoscomparison function.  This routine should take three arguments: the first
97*e992f068Schristostwo point to the @var{key} and to an array member, and the last is passed
98*e992f068Schristosdown unchanged from @code{bsearch_r}'s last argument.  It should return an
99*e992f068Schristosinteger less than, equal to, or greater than zero if the @var{key} object
100*e992f068Schristosis respectively less than, matching, or greater than the array member.
101*e992f068Schristos
102*e992f068Schristos@end deftypefn
103*e992f068Schristos
104012573ebSchristos@c argv.c:138
10516dce513Schristos@deftypefn Extension char** buildargv (char *@var{sp})
10616dce513Schristos
10716dce513SchristosGiven a pointer to a string, parse the string extracting fields
10816dce513Schristosseparated by whitespace and optionally enclosed within either single
10916dce513Schristosor double quotes (which are stripped off), and build a vector of
11016dce513Schristospointers to copies of the string for each field.  The input string
11116dce513Schristosremains unchanged.  The last element of the vector is followed by a
11216dce513Schristos@code{NULL} element.
11316dce513Schristos
11416dce513SchristosAll of the memory for the pointer array and copies of the string
11516dce513Schristosis obtained from @code{xmalloc}.  All of the memory can be returned to the
11616dce513Schristossystem with the single function call @code{freeargv}, which takes the
11716dce513Schristosreturned result of @code{buildargv}, as it's argument.
11816dce513Schristos
11916dce513SchristosReturns a pointer to the argument vector if successful.  Returns
12016dce513Schristos@code{NULL} if @var{sp} is @code{NULL} or if there is insufficient
12116dce513Schristosmemory to complete building the argument vector.
12216dce513Schristos
12316dce513SchristosIf the input is a null string (as opposed to a @code{NULL} pointer),
12416dce513Schristosthen buildarg returns an argument vector that has one arg, a null
12516dce513Schristosstring.
12616dce513Schristos
12716dce513Schristos@end deftypefn
12816dce513Schristos
12916dce513Schristos@c bzero.c:6
13016dce513Schristos@deftypefn Supplemental void bzero (char *@var{mem}, int @var{count})
13116dce513Schristos
13216dce513SchristosZeros @var{count} bytes starting at @var{mem}.  Use of this function
13316dce513Schristosis deprecated in favor of @code{memset}.
13416dce513Schristos
13516dce513Schristos@end deftypefn
13616dce513Schristos
13716dce513Schristos@c calloc.c:6
13816dce513Schristos@deftypefn Supplemental void* calloc (size_t @var{nelem}, size_t @var{elsize})
13916dce513Schristos
14016dce513SchristosUses @code{malloc} to allocate storage for @var{nelem} objects of
14116dce513Schristos@var{elsize} bytes each, then zeros the memory.
14216dce513Schristos
14316dce513Schristos@end deftypefn
14416dce513Schristos
14516dce513Schristos@c filename_cmp.c:201
14616dce513Schristos@deftypefn Extension int canonical_filename_eq (const char *@var{a}, const char *@var{b})
14716dce513Schristos
14816dce513SchristosReturn non-zero if file names @var{a} and @var{b} are equivalent.
14916dce513SchristosThis function compares the canonical versions of the filenames as returned by
15016dce513Schristos@code{lrealpath()}, so that so that different file names pointing to the same
15116dce513Schristosunderlying file are treated as being identical.
15216dce513Schristos
15316dce513Schristos@end deftypefn
15416dce513Schristos
15516dce513Schristos@c choose-temp.c:45
15616dce513Schristos@deftypefn Extension char* choose_temp_base (void)
15716dce513Schristos
15816dce513SchristosReturn a prefix for temporary file names or @code{NULL} if unable to
15916dce513Schristosfind one.  The current directory is chosen if all else fails so the
16016dce513Schristosprogram is exited if a temporary directory can't be found (@code{mktemp}
16116dce513Schristosfails).  The buffer for the result is obtained with @code{xmalloc}.
16216dce513Schristos
16316dce513SchristosThis function is provided for backwards compatibility only.  Its use is
16416dce513Schristosnot recommended.
16516dce513Schristos
16616dce513Schristos@end deftypefn
16716dce513Schristos
168012573ebSchristos@c make-temp-file.c:95
16916dce513Schristos@deftypefn Replacement const char* choose_tmpdir ()
17016dce513Schristos
17116dce513SchristosReturns a pointer to a directory path suitable for creating temporary
17216dce513Schristosfiles in.
17316dce513Schristos
17416dce513Schristos@end deftypefn
17516dce513Schristos
17616dce513Schristos@c clock.c:27
17716dce513Schristos@deftypefn Supplemental long clock (void)
17816dce513Schristos
17916dce513SchristosReturns an approximation of the CPU time used by the process as a
18016dce513Schristos@code{clock_t}; divide this number by @samp{CLOCKS_PER_SEC} to get the
18116dce513Schristosnumber of seconds used.
18216dce513Schristos
18316dce513Schristos@end deftypefn
18416dce513Schristos
18516dce513Schristos@c concat.c:24
18616dce513Schristos@deftypefn Extension char* concat (const char *@var{s1}, const char *@var{s2}, @
18716dce513Schristos  @dots{}, @code{NULL})
18816dce513Schristos
18916dce513SchristosConcatenate zero or more of strings and return the result in freshly
19016dce513Schristos@code{xmalloc}ed memory.  The argument list is terminated by the first
19116dce513Schristos@code{NULL} pointer encountered.  Pointers to empty strings are ignored.
19216dce513Schristos
19316dce513Schristos@end deftypefn
19416dce513Schristos
195*e992f068Schristos@c argv.c:495
19616dce513Schristos@deftypefn Extension int countargv (char * const *@var{argv})
19716dce513Schristos
19816dce513SchristosReturn the number of elements in @var{argv}.
19916dce513SchristosReturns zero if @var{argv} is NULL.
20016dce513Schristos
20116dce513Schristos@end deftypefn
20216dce513Schristos
203012573ebSchristos@c crc32.c:140
20416dce513Schristos@deftypefn Extension {unsigned int} crc32 (const unsigned char *@var{buf}, @
20516dce513Schristos  int @var{len}, unsigned int @var{init})
20616dce513Schristos
20716dce513SchristosCompute the 32-bit CRC of @var{buf} which has length @var{len}.  The
20816dce513Schristosstarting value is @var{init}; this may be used to compute the CRC of
20916dce513Schristosdata split across multiple buffers by passing the return value of each
21016dce513Schristoscall as the @var{init} parameter of the next.
21116dce513Schristos
212012573ebSchristosThis is used by the @command{gdb} remote protocol for the @samp{qCRC}
213012573ebSchristoscommand.  In order to get the same results as gdb for a block of data,
214012573ebSchristosyou must pass the first CRC parameter as @code{0xffffffff}.
21516dce513Schristos
21616dce513SchristosThis CRC can be specified as:
21716dce513Schristos
21816dce513Schristos  Width  : 32
21916dce513Schristos  Poly   : 0x04c11db7
22016dce513Schristos  Init   : parameter, typically 0xffffffff
22116dce513Schristos  RefIn  : false
22216dce513Schristos  RefOut : false
22316dce513Schristos  XorOut : 0
22416dce513Schristos
22516dce513SchristosThis differs from the "standard" CRC-32 algorithm in that the values
22616dce513Schristosare not reflected, and there is no final XOR value.  These differences
22716dce513Schristosmake it easy to compose the values of multiple blocks.
22816dce513Schristos
22916dce513Schristos@end deftypefn
23016dce513Schristos
231012573ebSchristos@c argv.c:59
23216dce513Schristos@deftypefn Extension char** dupargv (char * const *@var{vector})
23316dce513Schristos
23416dce513SchristosDuplicate an argument vector.  Simply scans through @var{vector},
23516dce513Schristosduplicating each argument until the terminating @code{NULL} is found.
23616dce513SchristosReturns a pointer to the argument vector if successful.  Returns
23716dce513Schristos@code{NULL} if there is insufficient memory to complete building the
23816dce513Schristosargument vector.
23916dce513Schristos
24016dce513Schristos@end deftypefn
24116dce513Schristos
242012573ebSchristos@c strerror.c:572
24316dce513Schristos@deftypefn Extension int errno_max (void)
24416dce513Schristos
24516dce513SchristosReturns the maximum @code{errno} value for which a corresponding
24616dce513Schristossymbolic name or message is available.  Note that in the case where we
24716dce513Schristosuse the @code{sys_errlist} supplied by the system, it is possible for
24816dce513Schristosthere to be more symbolic names than messages, or vice versa.  In
24916dce513Schristosfact, the manual page for @code{perror(3C)} explicitly warns that one
25016dce513Schristosshould check the size of the table (@code{sys_nerr}) before indexing
25116dce513Schristosit, since new error codes may be added to the system before they are
25216dce513Schristosadded to the table.  Thus @code{sys_nerr} might be smaller than value
25316dce513Schristosimplied by the largest @code{errno} value defined in @code{<errno.h>}.
25416dce513Schristos
25516dce513SchristosWe return the maximum value that can be used to obtain a meaningful
25616dce513Schristossymbolic name or message.
25716dce513Schristos
25816dce513Schristos@end deftypefn
25916dce513Schristos
260*e992f068Schristos@c argv.c:352
26116dce513Schristos@deftypefn Extension void expandargv (int *@var{argcp}, char ***@var{argvp})
26216dce513Schristos
26316dce513SchristosThe @var{argcp} and @code{argvp} arguments are pointers to the usual
26416dce513Schristos@code{argc} and @code{argv} arguments to @code{main}.  This function
26516dce513Schristoslooks for arguments that begin with the character @samp{@@}.  Any such
26616dce513Schristosarguments are interpreted as ``response files''.  The contents of the
26716dce513Schristosresponse file are interpreted as additional command line options.  In
26816dce513Schristosparticular, the file is separated into whitespace-separated strings;
26916dce513Schristoseach such string is taken as a command-line option.  The new options
27016dce513Schristosare inserted in place of the option naming the response file, and
27116dce513Schristos@code{*argcp} and @code{*argvp} will be updated.  If the value of
27216dce513Schristos@code{*argvp} is modified by this function, then the new value has
27316dce513Schristosbeen dynamically allocated and can be deallocated by the caller with
27416dce513Schristos@code{freeargv}.  However, most callers will simply call
27516dce513Schristos@code{expandargv} near the beginning of @code{main} and allow the
27616dce513Schristosoperating system to free the memory when the program exits.
27716dce513Schristos
27816dce513Schristos@end deftypefn
27916dce513Schristos
28016dce513Schristos@c fdmatch.c:23
28116dce513Schristos@deftypefn Extension int fdmatch (int @var{fd1}, int @var{fd2})
28216dce513Schristos
28316dce513SchristosCheck to see if two open file descriptors refer to the same file.
28416dce513SchristosThis is useful, for example, when we have an open file descriptor for
28516dce513Schristosan unnamed file, and the name of a file that we believe to correspond
28616dce513Schristosto that fd.  This can happen when we are exec'd with an already open
28716dce513Schristosfile (@code{stdout} for example) or from the SVR4 @file{/proc} calls
28816dce513Schristosthat return open file descriptors for mapped address spaces.  All we
28916dce513Schristoshave to do is open the file by name and check the two file descriptors
29016dce513Schristosfor a match, which is done by comparing major and minor device numbers
29116dce513Schristosand inode numbers.
29216dce513Schristos
29316dce513Schristos@end deftypefn
29416dce513Schristos
29516dce513Schristos@c fopen_unlocked.c:49
29616dce513Schristos@deftypefn Extension {FILE *} fdopen_unlocked (int @var{fildes}, @
29716dce513Schristos  const char * @var{mode})
29816dce513Schristos
29916dce513SchristosOpens and returns a @code{FILE} pointer via @code{fdopen}.  If the
30016dce513Schristosoperating system supports it, ensure that the stream is setup to avoid
30116dce513Schristosany multi-threaded locking.  Otherwise return the @code{FILE} pointer
30216dce513Schristosunchanged.
30316dce513Schristos
30416dce513Schristos@end deftypefn
30516dce513Schristos
30616dce513Schristos@c ffs.c:3
30716dce513Schristos@deftypefn Supplemental int ffs (int @var{valu})
30816dce513Schristos
30916dce513SchristosFind the first (least significant) bit set in @var{valu}.  Bits are
31016dce513Schristosnumbered from right to left, starting with bit 1 (corresponding to the
31116dce513Schristosvalue 1).  If @var{valu} is zero, zero is returned.
31216dce513Schristos
31316dce513Schristos@end deftypefn
31416dce513Schristos
31516dce513Schristos@c filename_cmp.c:37
31616dce513Schristos@deftypefn Extension int filename_cmp (const char *@var{s1}, const char *@var{s2})
31716dce513Schristos
31816dce513SchristosReturn zero if the two file names @var{s1} and @var{s2} are equivalent.
31916dce513SchristosIf not equivalent, the returned value is similar to what @code{strcmp}
32016dce513Schristoswould return.  In other words, it returns a negative value if @var{s1}
32116dce513Schristosis less than @var{s2}, or a positive value if @var{s2} is greater than
32216dce513Schristos@var{s2}.
32316dce513Schristos
32416dce513SchristosThis function does not normalize file names.  As a result, this function
32516dce513Schristoswill treat filenames that are spelled differently as different even in
32616dce513Schristosthe case when the two filenames point to the same underlying file.
32716dce513SchristosHowever, it does handle the fact that on DOS-like file systems, forward
32816dce513Schristosand backward slashes are equal.
32916dce513Schristos
33016dce513Schristos@end deftypefn
33116dce513Schristos
33216dce513Schristos@c filename_cmp.c:183
33316dce513Schristos@deftypefn Extension int filename_eq (const void *@var{s1}, const void *@var{s2})
33416dce513Schristos
33516dce513SchristosReturn non-zero if file names @var{s1} and @var{s2} are equivalent.
33616dce513SchristosThis function is for use with hashtab.c hash tables.
33716dce513Schristos
33816dce513Schristos@end deftypefn
33916dce513Schristos
34016dce513Schristos@c filename_cmp.c:152
34116dce513Schristos@deftypefn Extension hashval_t filename_hash (const void *@var{s})
34216dce513Schristos
34316dce513SchristosReturn the hash value for file name @var{s} that will be compared
34416dce513Schristosusing filename_cmp.
34516dce513SchristosThis function is for use with hashtab.c hash tables.
34616dce513Schristos
34716dce513Schristos@end deftypefn
34816dce513Schristos
34916dce513Schristos@c filename_cmp.c:94
35016dce513Schristos@deftypefn Extension int filename_ncmp (const char *@var{s1}, const char *@var{s2}, size_t @var{n})
35116dce513Schristos
35216dce513SchristosReturn zero if the two file names @var{s1} and @var{s2} are equivalent
35316dce513Schristosin range @var{n}.
35416dce513SchristosIf not equivalent, the returned value is similar to what @code{strncmp}
35516dce513Schristoswould return.  In other words, it returns a negative value if @var{s1}
35616dce513Schristosis less than @var{s2}, or a positive value if @var{s2} is greater than
35716dce513Schristos@var{s2}.
35816dce513Schristos
35916dce513SchristosThis function does not normalize file names.  As a result, this function
36016dce513Schristoswill treat filenames that are spelled differently as different even in
36116dce513Schristosthe case when the two filenames point to the same underlying file.
36216dce513SchristosHowever, it does handle the fact that on DOS-like file systems, forward
36316dce513Schristosand backward slashes are equal.
36416dce513Schristos
36516dce513Schristos@end deftypefn
36616dce513Schristos
36716dce513Schristos@c fnmatch.txh:1
36816dce513Schristos@deftypefn Replacement int fnmatch (const char *@var{pattern}, @
36916dce513Schristos  const char *@var{string}, int @var{flags})
37016dce513Schristos
37116dce513SchristosMatches @var{string} against @var{pattern}, returning zero if it
37216dce513Schristosmatches, @code{FNM_NOMATCH} if not.  @var{pattern} may contain the
37316dce513Schristoswildcards @code{?} to match any one character, @code{*} to match any
37416dce513Schristoszero or more characters, or a set of alternate characters in square
37516dce513Schristosbrackets, like @samp{[a-gt8]}, which match one character (@code{a}
37616dce513Schristosthrough @code{g}, or @code{t}, or @code{8}, in this example) if that one
37716dce513Schristoscharacter is in the set.  A set may be inverted (i.e., match anything
37816dce513Schristosexcept what's in the set) by giving @code{^} or @code{!} as the first
37916dce513Schristoscharacter in the set.  To include those characters in the set, list them
38016dce513Schristosas anything other than the first character of the set.  To include a
38116dce513Schristosdash in the set, list it last in the set.  A backslash character makes
38216dce513Schristosthe following character not special, so for example you could match
38316dce513Schristosagainst a literal asterisk with @samp{\*}.  To match a literal
38416dce513Schristosbackslash, use @samp{\\}.
38516dce513Schristos
38616dce513Schristos@code{flags} controls various aspects of the matching process, and is a
38716dce513Schristosboolean OR of zero or more of the following values (defined in
38816dce513Schristos@code{<fnmatch.h>}):
38916dce513Schristos
39016dce513Schristos@table @code
39116dce513Schristos
39216dce513Schristos@item FNM_PATHNAME
39316dce513Schristos@itemx FNM_FILE_NAME
39416dce513Schristos@var{string} is assumed to be a path name.  No wildcard will ever match
39516dce513Schristos@code{/}.
39616dce513Schristos
39716dce513Schristos@item FNM_NOESCAPE
39816dce513SchristosDo not interpret backslashes as quoting the following special character.
39916dce513Schristos
40016dce513Schristos@item FNM_PERIOD
40116dce513SchristosA leading period (at the beginning of @var{string}, or if
40216dce513Schristos@code{FNM_PATHNAME} after a slash) is not matched by @code{*} or
40316dce513Schristos@code{?} but must be matched explicitly.
40416dce513Schristos
40516dce513Schristos@item FNM_LEADING_DIR
40616dce513SchristosMeans that @var{string} also matches @var{pattern} if some initial part
40716dce513Schristosof @var{string} matches, and is followed by @code{/} and zero or more
40816dce513Schristoscharacters.  For example, @samp{foo*} would match either @samp{foobar}
40916dce513Schristosor @samp{foobar/grill}.
41016dce513Schristos
41116dce513Schristos@item FNM_CASEFOLD
41216dce513SchristosIgnores case when performing the comparison.
41316dce513Schristos
41416dce513Schristos@end table
41516dce513Schristos
41616dce513Schristos@end deftypefn
41716dce513Schristos
41816dce513Schristos@c fopen_unlocked.c:39
41916dce513Schristos@deftypefn Extension {FILE *} fopen_unlocked (const char *@var{path}, @
42016dce513Schristos  const char * @var{mode})
42116dce513Schristos
42216dce513SchristosOpens and returns a @code{FILE} pointer via @code{fopen}.  If the
42316dce513Schristosoperating system supports it, ensure that the stream is setup to avoid
42416dce513Schristosany multi-threaded locking.  Otherwise return the @code{FILE} pointer
42516dce513Schristosunchanged.
42616dce513Schristos
42716dce513Schristos@end deftypefn
42816dce513Schristos
429012573ebSchristos@c argv.c:93
43016dce513Schristos@deftypefn Extension void freeargv (char **@var{vector})
43116dce513Schristos
43216dce513SchristosFree an argument vector that was built using @code{buildargv}.  Simply
43316dce513Schristosscans through @var{vector}, freeing the memory for each argument until
43416dce513Schristosthe terminating @code{NULL} is found, and then frees @var{vector}
43516dce513Schristositself.
43616dce513Schristos
43716dce513Schristos@end deftypefn
43816dce513Schristos
43916dce513Schristos@c fopen_unlocked.c:59
44016dce513Schristos@deftypefn Extension {FILE *} freopen_unlocked (const char * @var{path}, @
44116dce513Schristos  const char * @var{mode}, FILE * @var{stream})
44216dce513Schristos
44316dce513SchristosOpens and returns a @code{FILE} pointer via @code{freopen}.  If the
44416dce513Schristosoperating system supports it, ensure that the stream is setup to avoid
44516dce513Schristosany multi-threaded locking.  Otherwise return the @code{FILE} pointer
44616dce513Schristosunchanged.
44716dce513Schristos
44816dce513Schristos@end deftypefn
44916dce513Schristos
450012573ebSchristos@c getruntime.c:86
45116dce513Schristos@deftypefn Replacement long get_run_time (void)
45216dce513Schristos
45316dce513SchristosReturns the time used so far, in microseconds.  If possible, this is
45416dce513Schristosthe time used by this process, else it is the elapsed time since the
45516dce513Schristosprocess started.
45616dce513Schristos
45716dce513Schristos@end deftypefn
45816dce513Schristos
45916dce513Schristos@c getcwd.c:6
46016dce513Schristos@deftypefn Supplemental char* getcwd (char *@var{pathname}, int @var{len})
46116dce513Schristos
46216dce513SchristosCopy the absolute pathname for the current working directory into
46316dce513Schristos@var{pathname}, which is assumed to point to a buffer of at least
46416dce513Schristos@var{len} bytes, and return a pointer to the buffer.  If the current
46516dce513Schristosdirectory's path doesn't fit in @var{len} characters, the result is
46616dce513Schristos@code{NULL} and @code{errno} is set.  If @var{pathname} is a null pointer,
46716dce513Schristos@code{getcwd} will obtain @var{len} bytes of space using
46816dce513Schristos@code{malloc}.
46916dce513Schristos
47016dce513Schristos@end deftypefn
47116dce513Schristos
47216dce513Schristos@c getpagesize.c:5
47316dce513Schristos@deftypefn Supplemental int getpagesize (void)
47416dce513Schristos
47516dce513SchristosReturns the number of bytes in a page of memory.  This is the
47616dce513Schristosgranularity of many of the system memory management routines.  No
47716dce513Schristosguarantee is made as to whether or not it is the same as the basic
47816dce513Schristosmemory management hardware page size.
47916dce513Schristos
48016dce513Schristos@end deftypefn
48116dce513Schristos
48216dce513Schristos@c getpwd.c:5
48316dce513Schristos@deftypefn Supplemental char* getpwd (void)
48416dce513Schristos
48516dce513SchristosReturns the current working directory.  This implementation caches the
48616dce513Schristosresult on the assumption that the process will not call @code{chdir}
48716dce513Schristosbetween calls to @code{getpwd}.
48816dce513Schristos
48916dce513Schristos@end deftypefn
49016dce513Schristos
49116dce513Schristos@c gettimeofday.c:12
49216dce513Schristos@deftypefn Supplemental int gettimeofday (struct timeval *@var{tp}, void *@var{tz})
49316dce513Schristos
49416dce513SchristosWrites the current time to @var{tp}.  This implementation requires
49516dce513Schristosthat @var{tz} be NULL.  Returns 0 on success, -1 on failure.
49616dce513Schristos
49716dce513Schristos@end deftypefn
49816dce513Schristos
49916dce513Schristos@c hex.c:33
50016dce513Schristos@deftypefn Extension void hex_init (void)
50116dce513Schristos
50216dce513SchristosInitializes the array mapping the current character set to
50316dce513Schristoscorresponding hex values.  This function must be called before any
50416dce513Schristoscall to @code{hex_p} or @code{hex_value}.  If you fail to call it, a
50516dce513Schristosdefault ASCII-based table will normally be used on ASCII systems.
50616dce513Schristos
50716dce513Schristos@end deftypefn
50816dce513Schristos
50916dce513Schristos@c hex.c:42
51016dce513Schristos@deftypefn Extension int hex_p (int @var{c})
51116dce513Schristos
51216dce513SchristosEvaluates to non-zero if the given character is a valid hex character,
51316dce513Schristosor zero if it is not.  Note that the value you pass will be cast to
51416dce513Schristos@code{unsigned char} within the macro.
51516dce513Schristos
51616dce513Schristos@end deftypefn
51716dce513Schristos
51816dce513Schristos@c hex.c:50
51916dce513Schristos@deftypefn Extension {unsigned int} hex_value (int @var{c})
52016dce513Schristos
52116dce513SchristosReturns the numeric equivalent of the given character when interpreted
52216dce513Schristosas a hexadecimal digit.  The result is undefined if you pass an
52316dce513Schristosinvalid hex digit.  Note that the value you pass will be cast to
52416dce513Schristos@code{unsigned char} within the macro.
52516dce513Schristos
52616dce513SchristosThe @code{hex_value} macro returns @code{unsigned int}, rather than
52716dce513Schristossigned @code{int}, to make it easier to use in parsing addresses from
52816dce513Schristoshex dump files: a signed @code{int} would be sign-extended when
52916dce513Schristosconverted to a wider unsigned type --- like @code{bfd_vma}, on some
53016dce513Schristossystems.
53116dce513Schristos
53216dce513Schristos@end deftypefn
53316dce513Schristos
534012573ebSchristos@c safe-ctype.c:24
53516dce513Schristos@defvr Extension HOST_CHARSET
53616dce513SchristosThis macro indicates the basic character set and encoding used by the
53716dce513Schristoshost: more precisely, the encoding used for character constants in
53816dce513Schristospreprocessor @samp{#if} statements (the C "execution character set").
53916dce513SchristosIt is defined by @file{safe-ctype.h}, and will be an integer constant
54016dce513Schristoswith one of the following values:
54116dce513Schristos
54216dce513Schristos@ftable @code
54316dce513Schristos@item HOST_CHARSET_UNKNOWN
54416dce513SchristosThe host character set is unknown - that is, not one of the next two
54516dce513Schristospossibilities.
54616dce513Schristos
54716dce513Schristos@item HOST_CHARSET_ASCII
54816dce513SchristosThe host character set is ASCII.
54916dce513Schristos
55016dce513Schristos@item HOST_CHARSET_EBCDIC
55116dce513SchristosThe host character set is some variant of EBCDIC.  (Only one of the
55216dce513Schristosnineteen EBCDIC varying characters is tested; exercise caution.)
55316dce513Schristos@end ftable
55416dce513Schristos@end defvr
55516dce513Schristos
556012573ebSchristos@c hashtab.c:327
55716dce513Schristos@deftypefn Supplemental htab_t htab_create_typed_alloc (size_t @var{size}, @
55816dce513Schristoshtab_hash @var{hash_f}, htab_eq @var{eq_f}, htab_del @var{del_f}, @
55916dce513Schristoshtab_alloc @var{alloc_tab_f}, htab_alloc @var{alloc_f}, @
56016dce513Schristoshtab_free @var{free_f})
56116dce513Schristos
56216dce513SchristosThis function creates a hash table that uses two different allocators
56316dce513Schristos@var{alloc_tab_f} and @var{alloc_f} to use for allocating the table itself
56416dce513Schristosand its entries respectively.  This is useful when variables of different
56516dce513Schristostypes need to be allocated with different allocators.
56616dce513Schristos
56716dce513SchristosThe created hash table is slightly larger than @var{size} and it is
56816dce513Schristosinitially empty (all the hash table entries are @code{HTAB_EMPTY_ENTRY}).
56916dce513SchristosThe function returns the created hash table, or @code{NULL} if memory
57016dce513Schristosallocation fails.
57116dce513Schristos
57216dce513Schristos@end deftypefn
57316dce513Schristos
57416dce513Schristos@c index.c:5
57516dce513Schristos@deftypefn Supplemental char* index (char *@var{s}, int @var{c})
57616dce513Schristos
57716dce513SchristosReturns a pointer to the first occurrence of the character @var{c} in
57816dce513Schristosthe string @var{s}, or @code{NULL} if not found.  The use of @code{index} is
57916dce513Schristosdeprecated in new programs in favor of @code{strchr}.
58016dce513Schristos
58116dce513Schristos@end deftypefn
58216dce513Schristos
58316dce513Schristos@c insque.c:6
58416dce513Schristos@deftypefn Supplemental void insque (struct qelem *@var{elem}, @
58516dce513Schristos  struct qelem *@var{pred})
58616dce513Schristos@deftypefnx Supplemental void remque (struct qelem *@var{elem})
58716dce513Schristos
58816dce513SchristosRoutines to manipulate queues built from doubly linked lists.  The
58916dce513Schristos@code{insque} routine inserts @var{elem} in the queue immediately
59016dce513Schristosafter @var{pred}.  The @code{remque} routine removes @var{elem} from
59116dce513Schristosits containing queue.  These routines expect to be passed pointers to
59216dce513Schristosstructures which have as their first members a forward pointer and a
59316dce513Schristosback pointer, like this prototype (although no prototype is provided):
59416dce513Schristos
59516dce513Schristos@example
59616dce513Schristosstruct qelem @{
59716dce513Schristos  struct qelem *q_forw;
59816dce513Schristos  struct qelem *q_back;
59916dce513Schristos  char q_data[];
60016dce513Schristos@};
60116dce513Schristos@end example
60216dce513Schristos
60316dce513Schristos@end deftypefn
60416dce513Schristos
605012573ebSchristos@c safe-ctype.c:45
60616dce513Schristos@deffn  Extension ISALPHA  (@var{c})
60716dce513Schristos@deffnx Extension ISALNUM  (@var{c})
60816dce513Schristos@deffnx Extension ISBLANK  (@var{c})
60916dce513Schristos@deffnx Extension ISCNTRL  (@var{c})
61016dce513Schristos@deffnx Extension ISDIGIT  (@var{c})
61116dce513Schristos@deffnx Extension ISGRAPH  (@var{c})
61216dce513Schristos@deffnx Extension ISLOWER  (@var{c})
61316dce513Schristos@deffnx Extension ISPRINT  (@var{c})
61416dce513Schristos@deffnx Extension ISPUNCT  (@var{c})
61516dce513Schristos@deffnx Extension ISSPACE  (@var{c})
61616dce513Schristos@deffnx Extension ISUPPER  (@var{c})
61716dce513Schristos@deffnx Extension ISXDIGIT (@var{c})
61816dce513Schristos
61916dce513SchristosThese twelve macros are defined by @file{safe-ctype.h}.  Each has the
62016dce513Schristossame meaning as the corresponding macro (with name in lowercase)
62116dce513Schristosdefined by the standard header @file{ctype.h}.  For example,
62216dce513Schristos@code{ISALPHA} returns true for alphabetic characters and false for
62316dce513Schristosothers.  However, there are two differences between these macros and
62416dce513Schristosthose provided by @file{ctype.h}:
62516dce513Schristos
62616dce513Schristos@itemize @bullet
62716dce513Schristos@item These macros are guaranteed to have well-defined behavior for all
62816dce513Schristosvalues representable by @code{signed char} and @code{unsigned char}, and
62916dce513Schristosfor @code{EOF}.
63016dce513Schristos
63116dce513Schristos@item These macros ignore the current locale; they are true for these
63216dce513Schristosfixed sets of characters:
63316dce513Schristos@multitable {@code{XDIGIT}} {yada yada yada yada yada yada yada yada}
63416dce513Schristos@item @code{ALPHA}  @tab @kbd{A-Za-z}
63516dce513Schristos@item @code{ALNUM}  @tab @kbd{A-Za-z0-9}
63616dce513Schristos@item @code{BLANK}  @tab @kbd{space tab}
63716dce513Schristos@item @code{CNTRL}  @tab @code{!PRINT}
63816dce513Schristos@item @code{DIGIT}  @tab @kbd{0-9}
63916dce513Schristos@item @code{GRAPH}  @tab @code{ALNUM || PUNCT}
64016dce513Schristos@item @code{LOWER}  @tab @kbd{a-z}
64116dce513Schristos@item @code{PRINT}  @tab @code{GRAPH ||} @kbd{space}
64216dce513Schristos@item @code{PUNCT}  @tab @kbd{`~!@@#$%^&*()_-=+[@{]@}\|;:'",<.>/?}
64316dce513Schristos@item @code{SPACE}  @tab @kbd{space tab \n \r \f \v}
64416dce513Schristos@item @code{UPPER}  @tab @kbd{A-Z}
64516dce513Schristos@item @code{XDIGIT} @tab @kbd{0-9A-Fa-f}
64616dce513Schristos@end multitable
64716dce513Schristos
64816dce513SchristosNote that, if the host character set is ASCII or a superset thereof,
64916dce513Schristosall these macros will return false for all values of @code{char} outside
65016dce513Schristosthe range of 7-bit ASCII.  In particular, both ISPRINT and ISCNTRL return
65116dce513Schristosfalse for characters with numeric values from 128 to 255.
65216dce513Schristos@end itemize
65316dce513Schristos@end deffn
65416dce513Schristos
655012573ebSchristos@c safe-ctype.c:94
65616dce513Schristos@deffn  Extension ISIDNUM         (@var{c})
65716dce513Schristos@deffnx Extension ISIDST          (@var{c})
65816dce513Schristos@deffnx Extension IS_VSPACE       (@var{c})
65916dce513Schristos@deffnx Extension IS_NVSPACE      (@var{c})
66016dce513Schristos@deffnx Extension IS_SPACE_OR_NUL (@var{c})
66116dce513Schristos@deffnx Extension IS_ISOBASIC     (@var{c})
66216dce513SchristosThese six macros are defined by @file{safe-ctype.h} and provide
66316dce513Schristosadditional character classes which are useful when doing lexical
66416dce513Schristosanalysis of C or similar languages.  They are true for the following
66516dce513Schristossets of characters:
66616dce513Schristos
66716dce513Schristos@multitable {@code{SPACE_OR_NUL}} {yada yada yada yada yada yada yada yada}
66816dce513Schristos@item @code{IDNUM}        @tab @kbd{A-Za-z0-9_}
66916dce513Schristos@item @code{IDST}         @tab @kbd{A-Za-z_}
67016dce513Schristos@item @code{VSPACE}       @tab @kbd{\r \n}
67116dce513Schristos@item @code{NVSPACE}      @tab @kbd{space tab \f \v \0}
67216dce513Schristos@item @code{SPACE_OR_NUL} @tab @code{VSPACE || NVSPACE}
67316dce513Schristos@item @code{ISOBASIC}     @tab @code{VSPACE || NVSPACE || PRINT}
67416dce513Schristos@end multitable
67516dce513Schristos@end deffn
67616dce513Schristos
67716dce513Schristos@c lbasename.c:23
67816dce513Schristos@deftypefn Replacement {const char*} lbasename (const char *@var{name})
67916dce513Schristos
68016dce513SchristosGiven a pointer to a string containing a typical pathname
68116dce513Schristos(@samp{/usr/src/cmd/ls/ls.c} for example), returns a pointer to the
68216dce513Schristoslast component of the pathname (@samp{ls.c} in this case).  The
68316dce513Schristosreturned pointer is guaranteed to lie within the original
68416dce513Schristosstring.  This latter fact is not true of many vendor C
68516dce513Schristoslibraries, which return special strings or modify the passed
68616dce513Schristosstrings for particular input.
68716dce513Schristos
68816dce513SchristosIn particular, the empty string returns the same empty string,
68916dce513Schristosand a path ending in @code{/} returns the empty string after it.
69016dce513Schristos
69116dce513Schristos@end deftypefn
69216dce513Schristos
69316dce513Schristos@c lrealpath.c:25
69416dce513Schristos@deftypefn Replacement {const char*} lrealpath (const char *@var{name})
69516dce513Schristos
69616dce513SchristosGiven a pointer to a string containing a pathname, returns a canonical
69716dce513Schristosversion of the filename.  Symlinks will be resolved, and ``.'' and ``..''
69816dce513Schristoscomponents will be simplified.  The returned value will be allocated using
69916dce513Schristos@code{malloc}, or @code{NULL} will be returned on a memory allocation error.
70016dce513Schristos
70116dce513Schristos@end deftypefn
70216dce513Schristos
703012573ebSchristos@c make-relative-prefix.c:23
70416dce513Schristos@deftypefn Extension {const char*} make_relative_prefix (const char *@var{progname}, @
70516dce513Schristos  const char *@var{bin_prefix}, const char *@var{prefix})
70616dce513Schristos
70716dce513SchristosGiven three paths @var{progname}, @var{bin_prefix}, @var{prefix},
70816dce513Schristosreturn the path that is in the same position relative to
70916dce513Schristos@var{progname}'s directory as @var{prefix} is relative to
71016dce513Schristos@var{bin_prefix}.  That is, a string starting with the directory
71116dce513Schristosportion of @var{progname}, followed by a relative pathname of the
71216dce513Schristosdifference between @var{bin_prefix} and @var{prefix}.
71316dce513Schristos
71416dce513SchristosIf @var{progname} does not contain any directory separators,
71516dce513Schristos@code{make_relative_prefix} will search @env{PATH} to find a program
71616dce513Schristosnamed @var{progname}.  Also, if @var{progname} is a symbolic link,
71716dce513Schristosthe symbolic link will be resolved.
71816dce513Schristos
71916dce513SchristosFor example, if @var{bin_prefix} is @code{/alpha/beta/gamma/gcc/delta},
72016dce513Schristos@var{prefix} is @code{/alpha/beta/gamma/omega/}, and @var{progname} is
72116dce513Schristos@code{/red/green/blue/gcc}, then this function will return
72216dce513Schristos@code{/red/green/blue/../../omega/}.
72316dce513Schristos
72416dce513SchristosThe return value is normally allocated via @code{malloc}.  If no
72516dce513Schristosrelative prefix can be found, return @code{NULL}.
72616dce513Schristos
72716dce513Schristos@end deftypefn
72816dce513Schristos
729012573ebSchristos@c make-temp-file.c:173
73016dce513Schristos@deftypefn Replacement char* make_temp_file (const char *@var{suffix})
73116dce513Schristos
73216dce513SchristosReturn a temporary file name (as a string) or @code{NULL} if unable to
73316dce513Schristoscreate one.  @var{suffix} is a suffix to append to the file name.  The
73416dce513Schristosstring is @code{malloc}ed, and the temporary file has been created.
73516dce513Schristos
73616dce513Schristos@end deftypefn
73716dce513Schristos
73816dce513Schristos@c memchr.c:3
73916dce513Schristos@deftypefn Supplemental void* memchr (const void *@var{s}, int @var{c}, @
74016dce513Schristos  size_t @var{n})
74116dce513Schristos
74216dce513SchristosThis function searches memory starting at @code{*@var{s}} for the
74316dce513Schristoscharacter @var{c}.  The search only ends with the first occurrence of
74416dce513Schristos@var{c}, or after @var{length} characters; in particular, a null
74516dce513Schristoscharacter does not terminate the search.  If the character @var{c} is
74616dce513Schristosfound within @var{length} characters of @code{*@var{s}}, a pointer
74716dce513Schristosto the character is returned.  If @var{c} is not found, then @code{NULL} is
74816dce513Schristosreturned.
74916dce513Schristos
75016dce513Schristos@end deftypefn
75116dce513Schristos
75216dce513Schristos@c memcmp.c:6
75316dce513Schristos@deftypefn Supplemental int memcmp (const void *@var{x}, const void *@var{y}, @
75416dce513Schristos  size_t @var{count})
75516dce513Schristos
75616dce513SchristosCompares the first @var{count} bytes of two areas of memory.  Returns
75716dce513Schristoszero if they are the same, a value less than zero if @var{x} is
75816dce513Schristoslexically less than @var{y}, or a value greater than zero if @var{x}
75916dce513Schristosis lexically greater than @var{y}.  Note that lexical order is determined
76016dce513Schristosas if comparing unsigned char arrays.
76116dce513Schristos
76216dce513Schristos@end deftypefn
76316dce513Schristos
76416dce513Schristos@c memcpy.c:6
76516dce513Schristos@deftypefn Supplemental void* memcpy (void *@var{out}, const void *@var{in}, @
76616dce513Schristos  size_t @var{length})
76716dce513Schristos
76816dce513SchristosCopies @var{length} bytes from memory region @var{in} to region
76916dce513Schristos@var{out}.  Returns a pointer to @var{out}.
77016dce513Schristos
77116dce513Schristos@end deftypefn
77216dce513Schristos
77316dce513Schristos@c memmem.c:20
77416dce513Schristos@deftypefn Supplemental void* memmem (const void *@var{haystack}, @
77516dce513Schristos  size_t @var{haystack_len} const void *@var{needle}, size_t @var{needle_len})
77616dce513Schristos
77716dce513SchristosReturns a pointer to the first occurrence of @var{needle} (length
77816dce513Schristos@var{needle_len}) in @var{haystack} (length @var{haystack_len}).
77916dce513SchristosReturns @code{NULL} if not found.
78016dce513Schristos
78116dce513Schristos@end deftypefn
78216dce513Schristos
78316dce513Schristos@c memmove.c:6
78416dce513Schristos@deftypefn Supplemental void* memmove (void *@var{from}, const void *@var{to}, @
78516dce513Schristos  size_t @var{count})
78616dce513Schristos
78716dce513SchristosCopies @var{count} bytes from memory area @var{from} to memory area
78816dce513Schristos@var{to}, returning a pointer to @var{to}.
78916dce513Schristos
79016dce513Schristos@end deftypefn
79116dce513Schristos
79216dce513Schristos@c mempcpy.c:23
79316dce513Schristos@deftypefn Supplemental void* mempcpy (void *@var{out}, const void *@var{in}, @
79416dce513Schristos  size_t @var{length})
79516dce513Schristos
79616dce513SchristosCopies @var{length} bytes from memory region @var{in} to region
79716dce513Schristos@var{out}.  Returns a pointer to @var{out} + @var{length}.
79816dce513Schristos
79916dce513Schristos@end deftypefn
80016dce513Schristos
80116dce513Schristos@c memset.c:6
80216dce513Schristos@deftypefn Supplemental void* memset (void *@var{s}, int @var{c}, @
80316dce513Schristos  size_t @var{count})
80416dce513Schristos
80516dce513SchristosSets the first @var{count} bytes of @var{s} to the constant byte
80616dce513Schristos@var{c}, returning a pointer to @var{s}.
80716dce513Schristos
80816dce513Schristos@end deftypefn
80916dce513Schristos
810012573ebSchristos@c mkstemps.c:60
81116dce513Schristos@deftypefn Replacement int mkstemps (char *@var{pattern}, int @var{suffix_len})
81216dce513Schristos
81316dce513SchristosGenerate a unique temporary file name from @var{pattern}.
81416dce513Schristos@var{pattern} has the form:
81516dce513Schristos
81616dce513Schristos@example
81716dce513Schristos   @var{path}/ccXXXXXX@var{suffix}
81816dce513Schristos@end example
81916dce513Schristos
82016dce513Schristos@var{suffix_len} tells us how long @var{suffix} is (it can be zero
82116dce513Schristoslength).  The last six characters of @var{pattern} before @var{suffix}
82216dce513Schristosmust be @samp{XXXXXX}; they are replaced with a string that makes the
82316dce513Schristosfilename unique.  Returns a file descriptor open on the file for
82416dce513Schristosreading and writing.
82516dce513Schristos
82616dce513Schristos@end deftypefn
82716dce513Schristos
82816dce513Schristos@c pexecute.txh:278
82916dce513Schristos@deftypefn Extension void pex_free (struct pex_obj @var{obj})
83016dce513Schristos
83116dce513SchristosClean up and free all data associated with @var{obj}.  If you have not
83216dce513Schristosyet called @code{pex_get_times} or @code{pex_get_status}, this will
83316dce513Schristostry to kill the subprocesses.
83416dce513Schristos
83516dce513Schristos@end deftypefn
83616dce513Schristos
83716dce513Schristos@c pexecute.txh:251
83816dce513Schristos@deftypefn Extension int pex_get_status (struct pex_obj *@var{obj}, @
83916dce513Schristos  int @var{count}, int *@var{vector})
84016dce513Schristos
84116dce513SchristosReturns the exit status of all programs run using @var{obj}.
84216dce513Schristos@var{count} is the number of results expected.  The results will be
84316dce513Schristosplaced into @var{vector}.  The results are in the order of the calls
84416dce513Schristosto @code{pex_run}.  Returns 0 on error, 1 on success.
84516dce513Schristos
84616dce513Schristos@end deftypefn
84716dce513Schristos
84816dce513Schristos@c pexecute.txh:261
84916dce513Schristos@deftypefn Extension int pex_get_times (struct pex_obj *@var{obj}, @
85016dce513Schristos  int @var{count}, struct pex_time *@var{vector})
85116dce513Schristos
85216dce513SchristosReturns the process execution times of all programs run using
85316dce513Schristos@var{obj}.  @var{count} is the number of results expected.  The
85416dce513Schristosresults will be placed into @var{vector}.  The results are in the
85516dce513Schristosorder of the calls to @code{pex_run}.  Returns 0 on error, 1 on
85616dce513Schristossuccess.
85716dce513Schristos
85816dce513Schristos@code{struct pex_time} has the following fields of the type
85916dce513Schristos@code{unsigned long}: @code{user_seconds},
86016dce513Schristos@code{user_microseconds}, @code{system_seconds},
86116dce513Schristos@code{system_microseconds}.  On systems which do not support reporting
86216dce513Schristosprocess times, all the fields will be set to @code{0}.
86316dce513Schristos
86416dce513Schristos@end deftypefn
86516dce513Schristos
86616dce513Schristos@c pexecute.txh:2
86716dce513Schristos@deftypefn Extension {struct pex_obj *} pex_init (int @var{flags}, @
86816dce513Schristos  const char *@var{pname}, const char *@var{tempbase})
86916dce513Schristos
87016dce513SchristosPrepare to execute one or more programs, with standard output of each
87116dce513Schristosprogram fed to standard input of the next.  This is a system
87216dce513Schristosindependent interface to execute a pipeline.
87316dce513Schristos
87416dce513Schristos@var{flags} is a bitwise combination of the following:
87516dce513Schristos
87616dce513Schristos@table @code
87716dce513Schristos
87816dce513Schristos@vindex PEX_RECORD_TIMES
87916dce513Schristos@item PEX_RECORD_TIMES
88016dce513SchristosRecord subprocess times if possible.
88116dce513Schristos
88216dce513Schristos@vindex PEX_USE_PIPES
88316dce513Schristos@item PEX_USE_PIPES
88416dce513SchristosUse pipes for communication between processes, if possible.
88516dce513Schristos
88616dce513Schristos@vindex PEX_SAVE_TEMPS
88716dce513Schristos@item PEX_SAVE_TEMPS
88816dce513SchristosDon't delete temporary files used for communication between
88916dce513Schristosprocesses.
89016dce513Schristos
89116dce513Schristos@end table
89216dce513Schristos
89316dce513Schristos@var{pname} is the name of program to be executed, used in error
89416dce513Schristosmessages.  @var{tempbase} is a base name to use for any required
89516dce513Schristostemporary files; it may be @code{NULL} to use a randomly chosen name.
89616dce513Schristos
89716dce513Schristos@end deftypefn
89816dce513Schristos
89916dce513Schristos@c pexecute.txh:161
90016dce513Schristos@deftypefn Extension {FILE *} pex_input_file (struct pex_obj *@var{obj}, @
90116dce513Schristos  int @var{flags}, const char *@var{in_name})
90216dce513Schristos
90316dce513SchristosReturn a stream for a temporary file to pass to the first program in
90416dce513Schristosthe pipeline as input.
90516dce513Schristos
90616dce513SchristosThe name of the input file is chosen according to the same rules
90716dce513Schristos@code{pex_run} uses to choose output file names, based on
90816dce513Schristos@var{in_name}, @var{obj} and the @code{PEX_SUFFIX} bit in @var{flags}.
90916dce513Schristos
91016dce513SchristosDon't call @code{fclose} on the returned stream; the first call to
91116dce513Schristos@code{pex_run} closes it automatically.
91216dce513Schristos
91316dce513SchristosIf @var{flags} includes @code{PEX_BINARY_OUTPUT}, open the stream in
91416dce513Schristosbinary mode; otherwise, open it in the default mode.  Including
91516dce513Schristos@code{PEX_BINARY_OUTPUT} in @var{flags} has no effect on Unix.
91616dce513Schristos@end deftypefn
91716dce513Schristos
91816dce513Schristos@c pexecute.txh:179
91916dce513Schristos@deftypefn Extension {FILE *} pex_input_pipe (struct pex_obj *@var{obj}, @
92016dce513Schristos  int @var{binary})
92116dce513Schristos
92216dce513SchristosReturn a stream @var{fp} for a pipe connected to the standard input of
92316dce513Schristosthe first program in the pipeline; @var{fp} is opened for writing.
92416dce513SchristosYou must have passed @code{PEX_USE_PIPES} to the @code{pex_init} call
92516dce513Schristosthat returned @var{obj}.
92616dce513Schristos
92716dce513SchristosYou must close @var{fp} using @code{fclose} yourself when you have
92816dce513Schristosfinished writing data to the pipeline.
92916dce513Schristos
93016dce513SchristosThe file descriptor underlying @var{fp} is marked not to be inherited
93116dce513Schristosby child processes.
93216dce513Schristos
93316dce513SchristosOn systems that do not support pipes, this function returns
93416dce513Schristos@code{NULL}, and sets @code{errno} to @code{EINVAL}.  If you would
93516dce513Schristoslike to write code that is portable to all systems the @code{pex}
93616dce513Schristosfunctions support, consider using @code{pex_input_file} instead.
93716dce513Schristos
93816dce513SchristosThere are two opportunities for deadlock using
93916dce513Schristos@code{pex_input_pipe}:
94016dce513Schristos
94116dce513Schristos@itemize @bullet
94216dce513Schristos@item
94316dce513SchristosMost systems' pipes can buffer only a fixed amount of data; a process
94416dce513Schristosthat writes to a full pipe blocks.  Thus, if you write to @file{fp}
94516dce513Schristosbefore starting the first process, you run the risk of blocking when
94616dce513Schristosthere is no child process yet to read the data and allow you to
94716dce513Schristoscontinue.  @code{pex_input_pipe} makes no promises about the
94816dce513Schristossize of the pipe's buffer, so if you need to write any data at all
94916dce513Schristosbefore starting the first process in the pipeline, consider using
95016dce513Schristos@code{pex_input_file} instead.
95116dce513Schristos
95216dce513Schristos@item
95316dce513SchristosUsing @code{pex_input_pipe} and @code{pex_read_output} together
95416dce513Schristosmay also cause deadlock.  If the output pipe fills up, so that each
95516dce513Schristosprogram in the pipeline is waiting for the next to read more data, and
95616dce513Schristosyou fill the input pipe by writing more data to @var{fp}, then there
95716dce513Schristosis no way to make progress: the only process that could read data from
95816dce513Schristosthe output pipe is you, but you are blocked on the input pipe.
95916dce513Schristos
96016dce513Schristos@end itemize
96116dce513Schristos
96216dce513Schristos@end deftypefn
96316dce513Schristos
96416dce513Schristos@c pexecute.txh:286
96516dce513Schristos@deftypefn Extension {const char *} pex_one (int @var{flags}, @
96616dce513Schristos  const char *@var{executable}, char * const *@var{argv}, @
96716dce513Schristos  const char *@var{pname}, const char *@var{outname}, const char *@var{errname}, @
96816dce513Schristos  int *@var{status}, int *@var{err})
96916dce513Schristos
97016dce513SchristosAn interface to permit the easy execution of a
97116dce513Schristossingle program.  The return value and most of the parameters are as
97216dce513Schristosfor a call to @code{pex_run}.  @var{flags} is restricted to a
97316dce513Schristoscombination of @code{PEX_SEARCH}, @code{PEX_STDERR_TO_STDOUT}, and
97416dce513Schristos@code{PEX_BINARY_OUTPUT}.  @var{outname} is interpreted as if
97516dce513Schristos@code{PEX_LAST} were set.  On a successful return, @code{*@var{status}} will
97616dce513Schristosbe set to the exit status of the program.
97716dce513Schristos
97816dce513Schristos@end deftypefn
97916dce513Schristos
98016dce513Schristos@c pexecute.txh:237
98116dce513Schristos@deftypefn Extension {FILE *} pex_read_err (struct pex_obj *@var{obj}, @
98216dce513Schristos  int @var{binary})
98316dce513Schristos
98416dce513SchristosReturns a @code{FILE} pointer which may be used to read the standard
98516dce513Schristoserror of the last program in the pipeline.  When this is used,
98616dce513Schristos@code{PEX_LAST} should not be used in a call to @code{pex_run}.  After
98716dce513Schristosthis is called, @code{pex_run} may no longer be called with the same
98816dce513Schristos@var{obj}.  @var{binary} should be non-zero if the file should be
98916dce513Schristosopened in binary mode.  Don't call @code{fclose} on the returned file;
99016dce513Schristosit will be closed by @code{pex_free}.
99116dce513Schristos
99216dce513Schristos@end deftypefn
99316dce513Schristos
99416dce513Schristos@c pexecute.txh:224
99516dce513Schristos@deftypefn Extension {FILE *} pex_read_output (struct pex_obj *@var{obj}, @
99616dce513Schristos  int @var{binary})
99716dce513Schristos
99816dce513SchristosReturns a @code{FILE} pointer which may be used to read the standard
99916dce513Schristosoutput of the last program in the pipeline.  When this is used,
100016dce513Schristos@code{PEX_LAST} should not be used in a call to @code{pex_run}.  After
100116dce513Schristosthis is called, @code{pex_run} may no longer be called with the same
100216dce513Schristos@var{obj}.  @var{binary} should be non-zero if the file should be
100316dce513Schristosopened in binary mode.  Don't call @code{fclose} on the returned file;
100416dce513Schristosit will be closed by @code{pex_free}.
100516dce513Schristos
100616dce513Schristos@end deftypefn
100716dce513Schristos
100816dce513Schristos@c pexecute.txh:34
100916dce513Schristos@deftypefn Extension {const char *} pex_run (struct pex_obj *@var{obj}, @
101016dce513Schristos  int @var{flags}, const char *@var{executable}, char * const *@var{argv}, @
101116dce513Schristos  const char *@var{outname}, const char *@var{errname}, int *@var{err})
101216dce513Schristos
101316dce513SchristosExecute one program in a pipeline.  On success this returns
101416dce513Schristos@code{NULL}.  On failure it returns an error message, a statically
101516dce513Schristosallocated string.
101616dce513Schristos
101716dce513Schristos@var{obj} is returned by a previous call to @code{pex_init}.
101816dce513Schristos
101916dce513Schristos@var{flags} is a bitwise combination of the following:
102016dce513Schristos
102116dce513Schristos@table @code
102216dce513Schristos
102316dce513Schristos@vindex PEX_LAST
102416dce513Schristos@item PEX_LAST
102516dce513SchristosThis must be set on the last program in the pipeline.  In particular,
102616dce513Schristosit should be set when executing a single program.  The standard output
102716dce513Schristosof the program will be sent to @var{outname}, or, if @var{outname} is
102816dce513Schristos@code{NULL}, to the standard output of the calling program.  Do @emph{not}
102916dce513Schristosset this bit if you want to call @code{pex_read_output}
103016dce513Schristos(described below).  After a call to @code{pex_run} with this bit set,
103116dce513Schristos@var{pex_run} may no longer be called with the same @var{obj}.
103216dce513Schristos
103316dce513Schristos@vindex PEX_SEARCH
103416dce513Schristos@item PEX_SEARCH
103516dce513SchristosSearch for the program using the user's executable search path.
103616dce513Schristos
103716dce513Schristos@vindex PEX_SUFFIX
103816dce513Schristos@item PEX_SUFFIX
103916dce513Schristos@var{outname} is a suffix.  See the description of @var{outname},
104016dce513Schristosbelow.
104116dce513Schristos
104216dce513Schristos@vindex PEX_STDERR_TO_STDOUT
104316dce513Schristos@item PEX_STDERR_TO_STDOUT
104416dce513SchristosSend the program's standard error to standard output, if possible.
104516dce513Schristos
104616dce513Schristos@vindex PEX_BINARY_INPUT
104716dce513Schristos@vindex PEX_BINARY_OUTPUT
104816dce513Schristos@vindex PEX_BINARY_ERROR
104916dce513Schristos@item PEX_BINARY_INPUT
105016dce513Schristos@itemx PEX_BINARY_OUTPUT
105116dce513Schristos@itemx PEX_BINARY_ERROR
105216dce513SchristosThe standard input (output or error) of the program should be read (written) in
105316dce513Schristosbinary mode rather than text mode.  These flags are ignored on systems
105416dce513Schristoswhich do not distinguish binary mode and text mode, such as Unix.  For
105516dce513Schristosproper behavior these flags should match appropriately---a call to
105616dce513Schristos@code{pex_run} using @code{PEX_BINARY_OUTPUT} should be followed by a
105716dce513Schristoscall using @code{PEX_BINARY_INPUT}.
105816dce513Schristos
105916dce513Schristos@vindex PEX_STDERR_TO_PIPE
106016dce513Schristos@item PEX_STDERR_TO_PIPE
106116dce513SchristosSend the program's standard error to a pipe, if possible.  This flag
106216dce513Schristoscannot be specified together with @code{PEX_STDERR_TO_STDOUT}.  This
106316dce513Schristosflag can be specified only on the last program in pipeline.
106416dce513Schristos
106516dce513Schristos@end table
106616dce513Schristos
106716dce513Schristos@var{executable} is the program to execute.  @var{argv} is the set of
106816dce513Schristosarguments to pass to the program; normally @code{@var{argv}[0]} will
106916dce513Schristosbe a copy of @var{executable}.
107016dce513Schristos
107116dce513Schristos@var{outname} is used to set the name of the file to use for standard
107216dce513Schristosoutput.  There are two cases in which no output file will be used:
107316dce513Schristos
107416dce513Schristos@enumerate
107516dce513Schristos@item
107616dce513Schristosif @code{PEX_LAST} is not set in @var{flags}, and @code{PEX_USE_PIPES}
107716dce513Schristoswas set in the call to @code{pex_init}, and the system supports pipes
107816dce513Schristos
107916dce513Schristos@item
108016dce513Schristosif @code{PEX_LAST} is set in @var{flags}, and @var{outname} is
108116dce513Schristos@code{NULL}
108216dce513Schristos@end enumerate
108316dce513Schristos
108416dce513Schristos@noindent
108516dce513SchristosOtherwise the code will use a file to hold standard
108616dce513Schristosoutput.  If @code{PEX_LAST} is not set, this file is considered to be
108716dce513Schristosa temporary file, and it will be removed when no longer needed, unless
108816dce513Schristos@code{PEX_SAVE_TEMPS} was set in the call to @code{pex_init}.
108916dce513Schristos
109016dce513SchristosThere are two cases to consider when setting the name of the file to
109116dce513Schristoshold standard output.
109216dce513Schristos
109316dce513Schristos@enumerate
109416dce513Schristos@item
109516dce513Schristos@code{PEX_SUFFIX} is set in @var{flags}.  In this case
109616dce513Schristos@var{outname} may not be @code{NULL}.  If the @var{tempbase} parameter
109716dce513Schristosto @code{pex_init} was not @code{NULL}, then the output file name is
109816dce513Schristosthe concatenation of @var{tempbase} and @var{outname}.  If
109916dce513Schristos@var{tempbase} was @code{NULL}, then the output file name is a random
110016dce513Schristosfile name ending in @var{outname}.
110116dce513Schristos
110216dce513Schristos@item
110316dce513Schristos@code{PEX_SUFFIX} was not set in @var{flags}.  In this
110416dce513Schristoscase, if @var{outname} is not @code{NULL}, it is used as the output
110516dce513Schristosfile name.  If @var{outname} is @code{NULL}, and @var{tempbase} was
110616dce513Schristosnot NULL, the output file name is randomly chosen using
110716dce513Schristos@var{tempbase}.  Otherwise the output file name is chosen completely
110816dce513Schristosat random.
110916dce513Schristos@end enumerate
111016dce513Schristos
111116dce513Schristos@var{errname} is the file name to use for standard error output.  If
111216dce513Schristosit is @code{NULL}, standard error is the same as the caller's.
111316dce513SchristosOtherwise, standard error is written to the named file.
111416dce513Schristos
111516dce513SchristosOn an error return, the code sets @code{*@var{err}} to an @code{errno}
111616dce513Schristosvalue, or to 0 if there is no relevant @code{errno}.
111716dce513Schristos
111816dce513Schristos@end deftypefn
111916dce513Schristos
112016dce513Schristos@c pexecute.txh:145
112116dce513Schristos@deftypefn Extension {const char *} pex_run_in_environment (struct pex_obj *@var{obj}, @
112216dce513Schristos  int @var{flags}, const char *@var{executable}, char * const *@var{argv}, @
112316dce513Schristos  char * const *@var{env}, int @var{env_size}, const char *@var{outname}, @
112416dce513Schristos  const char *@var{errname}, int *@var{err})
112516dce513Schristos
112616dce513SchristosExecute one program in a pipeline, permitting the environment for the
112716dce513Schristosprogram to be specified.  Behaviour and parameters not listed below are
112816dce513Schristosas for @code{pex_run}.
112916dce513Schristos
113016dce513Schristos@var{env} is the environment for the child process, specified as an array of
113116dce513Schristoscharacter pointers.  Each element of the array should point to a string of the
113216dce513Schristosform @code{VAR=VALUE}, with the exception of the last element that must be
113316dce513Schristos@code{NULL}.
113416dce513Schristos
113516dce513Schristos@end deftypefn
113616dce513Schristos
113716dce513Schristos@c pexecute.txh:301
113816dce513Schristos@deftypefn Extension int pexecute (const char *@var{program}, @
113916dce513Schristos  char * const *@var{argv}, const char *@var{this_pname}, @
114016dce513Schristos  const char *@var{temp_base}, char **@var{errmsg_fmt}, @
114116dce513Schristos  char **@var{errmsg_arg}, int @var{flags})
114216dce513Schristos
114316dce513SchristosThis is the old interface to execute one or more programs.  It is
114416dce513Schristosstill supported for compatibility purposes, but is no longer
114516dce513Schristosdocumented.
114616dce513Schristos
114716dce513Schristos@end deftypefn
114816dce513Schristos
114916dce513Schristos@c strsignal.c:541
115016dce513Schristos@deftypefn Supplemental void psignal (int @var{signo}, char *@var{message})
115116dce513Schristos
115216dce513SchristosPrint @var{message} to the standard error, followed by a colon,
115316dce513Schristosfollowed by the description of the signal specified by @var{signo},
115416dce513Schristosfollowed by a newline.
115516dce513Schristos
115616dce513Schristos@end deftypefn
115716dce513Schristos
115816dce513Schristos@c putenv.c:21
115916dce513Schristos@deftypefn Supplemental int putenv (const char *@var{string})
116016dce513Schristos
116116dce513SchristosUses @code{setenv} or @code{unsetenv} to put @var{string} into
116216dce513Schristosthe environment or remove it.  If @var{string} is of the form
116316dce513Schristos@samp{name=value} the string is added; if no @samp{=} is present the
116416dce513Schristosname is unset/removed.
116516dce513Schristos
116616dce513Schristos@end deftypefn
116716dce513Schristos
116816dce513Schristos@c pexecute.txh:312
116916dce513Schristos@deftypefn Extension int pwait (int @var{pid}, int *@var{status}, int @var{flags})
117016dce513Schristos
117116dce513SchristosAnother part of the old execution interface.
117216dce513Schristos
117316dce513Schristos@end deftypefn
117416dce513Schristos
117516dce513Schristos@c random.c:39
117616dce513Schristos@deftypefn Supplement {long int} random (void)
117716dce513Schristos@deftypefnx Supplement void srandom (unsigned int @var{seed})
117816dce513Schristos@deftypefnx Supplement void* initstate (unsigned int @var{seed}, @
117916dce513Schristos  void *@var{arg_state}, unsigned long @var{n})
118016dce513Schristos@deftypefnx Supplement void* setstate (void *@var{arg_state})
118116dce513Schristos
118216dce513SchristosRandom number functions.  @code{random} returns a random number in the
118316dce513Schristosrange 0 to @code{LONG_MAX}.  @code{srandom} initializes the random
118416dce513Schristosnumber generator to some starting point determined by @var{seed}
118516dce513Schristos(else, the values returned by @code{random} are always the same for each
118616dce513Schristosrun of the program).  @code{initstate} and @code{setstate} allow fine-grained
118716dce513Schristoscontrol over the state of the random number generator.
118816dce513Schristos
118916dce513Schristos@end deftypefn
119016dce513Schristos
119116dce513Schristos@c concat.c:160
119216dce513Schristos@deftypefn Extension char* reconcat (char *@var{optr}, const char *@var{s1}, @
119316dce513Schristos  @dots{}, @code{NULL})
119416dce513Schristos
119516dce513SchristosSame as @code{concat}, except that if @var{optr} is not @code{NULL} it
119616dce513Schristosis freed after the string is created.  This is intended to be useful
119716dce513Schristoswhen you're extending an existing string or building up a string in a
119816dce513Schristosloop:
119916dce513Schristos
120016dce513Schristos@example
120116dce513Schristos  str = reconcat (str, "pre-", str, NULL);
120216dce513Schristos@end example
120316dce513Schristos
120416dce513Schristos@end deftypefn
120516dce513Schristos
120616dce513Schristos@c rename.c:6
120716dce513Schristos@deftypefn Supplemental int rename (const char *@var{old}, const char *@var{new})
120816dce513Schristos
120916dce513SchristosRenames a file from @var{old} to @var{new}.  If @var{new} already
121016dce513Schristosexists, it is removed.
121116dce513Schristos
121216dce513Schristos@end deftypefn
121316dce513Schristos
121416dce513Schristos@c rindex.c:5
121516dce513Schristos@deftypefn Supplemental char* rindex (const char *@var{s}, int @var{c})
121616dce513Schristos
121716dce513SchristosReturns a pointer to the last occurrence of the character @var{c} in
121816dce513Schristosthe string @var{s}, or @code{NULL} if not found.  The use of @code{rindex} is
121916dce513Schristosdeprecated in new programs in favor of @code{strrchr}.
122016dce513Schristos
122116dce513Schristos@end deftypefn
122216dce513Schristos
1223012573ebSchristos@c setenv.c:22
122416dce513Schristos@deftypefn Supplemental int setenv (const char *@var{name}, @
122516dce513Schristos  const char *@var{value}, int @var{overwrite})
122616dce513Schristos@deftypefnx Supplemental void unsetenv (const char *@var{name})
122716dce513Schristos
122816dce513Schristos@code{setenv} adds @var{name} to the environment with value
122916dce513Schristos@var{value}.  If the name was already present in the environment,
123016dce513Schristosthe new value will be stored only if @var{overwrite} is nonzero.
123116dce513SchristosThe companion @code{unsetenv} function removes @var{name} from the
123216dce513Schristosenvironment.  This implementation is not safe for multithreaded code.
123316dce513Schristos
123416dce513Schristos@end deftypefn
123516dce513Schristos
123616dce513Schristos@c setproctitle.c:31
123716dce513Schristos@deftypefn Supplemental void setproctitle (const char *@var{fmt}, ...)
123816dce513Schristos
123916dce513SchristosSet the title of a process to @var{fmt}. va args not supported for now,
124016dce513Schristosbut defined for compatibility with BSD.
124116dce513Schristos
124216dce513Schristos@end deftypefn
124316dce513Schristos
124416dce513Schristos@c strsignal.c:348
124516dce513Schristos@deftypefn Extension int signo_max (void)
124616dce513Schristos
124716dce513SchristosReturns the maximum signal value for which a corresponding symbolic
124816dce513Schristosname or message is available.  Note that in the case where we use the
124916dce513Schristos@code{sys_siglist} supplied by the system, it is possible for there to
125016dce513Schristosbe more symbolic names than messages, or vice versa.  In fact, the
125116dce513Schristosmanual page for @code{psignal(3b)} explicitly warns that one should
125216dce513Schristoscheck the size of the table (@code{NSIG}) before indexing it, since
125316dce513Schristosnew signal codes may be added to the system before they are added to
125416dce513Schristosthe table.  Thus @code{NSIG} might be smaller than value implied by
125516dce513Schristosthe largest signo value defined in @code{<signal.h>}.
125616dce513Schristos
125716dce513SchristosWe return the maximum value that can be used to obtain a meaningful
125816dce513Schristossymbolic name or message.
125916dce513Schristos
126016dce513Schristos@end deftypefn
126116dce513Schristos
126216dce513Schristos@c sigsetmask.c:8
126316dce513Schristos@deftypefn Supplemental int sigsetmask (int @var{set})
126416dce513Schristos
126516dce513SchristosSets the signal mask to the one provided in @var{set} and returns
126616dce513Schristosthe old mask (which, for libiberty's implementation, will always
126716dce513Schristosbe the value @code{1}).
126816dce513Schristos
126916dce513Schristos@end deftypefn
127016dce513Schristos
127116dce513Schristos@c simple-object.txh:96
127216dce513Schristos@deftypefn Extension {const char *} simple_object_attributes_compare @
127316dce513Schristos  (simple_object_attributes *@var{attrs1}, simple_object_attributes *@var{attrs2}, @
127416dce513Schristos   int *@var{err})
127516dce513Schristos
127616dce513SchristosCompare @var{attrs1} and @var{attrs2}.  If they could be linked
127716dce513Schristostogether without error, return @code{NULL}.  Otherwise, return an
127816dce513Schristoserror message and set @code{*@var{err}} to an errno value or @code{0}
127916dce513Schristosif there is no relevant errno.
128016dce513Schristos
128116dce513Schristos@end deftypefn
128216dce513Schristos
128316dce513Schristos@c simple-object.txh:81
128416dce513Schristos@deftypefn Extension {simple_object_attributes *} simple_object_fetch_attributes @
128516dce513Schristos  (simple_object_read *@var{simple_object}, const char **@var{errmsg}, int *@var{err})
128616dce513Schristos
128716dce513SchristosFetch the attributes of @var{simple_object}.  The attributes are
128816dce513Schristosinternal information such as the format of the object file, or the
128916dce513Schristosarchitecture it was compiled for.  This information will persist until
129016dce513Schristos@code{simple_object_attributes_release} is called, even if
129116dce513Schristos@var{simple_object} itself is released.
129216dce513Schristos
129316dce513SchristosOn error this returns @code{NULL}, sets @code{*@var{errmsg}} to an
129416dce513Schristoserror message, and sets @code{*@var{err}} to an errno value or
129516dce513Schristos@code{0} if there is no relevant errno.
129616dce513Schristos
129716dce513Schristos@end deftypefn
129816dce513Schristos
129916dce513Schristos@c simple-object.txh:49
130016dce513Schristos@deftypefn Extension {int} simple_object_find_section @
130116dce513Schristos  (simple_object_read *@var{simple_object} off_t *@var{offset}, @
130216dce513Schristos  off_t *@var{length}, const char **@var{errmsg}, int *@var{err})
130316dce513Schristos
130416dce513SchristosLook for the section @var{name} in @var{simple_object}.  This returns
130516dce513Schristosinformation for the first section with that name.
130616dce513Schristos
130716dce513SchristosIf found, return 1 and set @code{*@var{offset}} to the offset in the
130816dce513Schristosfile of the section contents and set @code{*@var{length}} to the
130916dce513Schristoslength of the section contents.  The value in @code{*@var{offset}}
131016dce513Schristoswill be relative to the offset passed to
131116dce513Schristos@code{simple_object_open_read}.
131216dce513Schristos
131316dce513SchristosIf the section is not found, and no error occurs,
131416dce513Schristos@code{simple_object_find_section} returns @code{0} and set
131516dce513Schristos@code{*@var{errmsg}} to @code{NULL}.
131616dce513Schristos
131716dce513SchristosIf an error occurs, @code{simple_object_find_section} returns
131816dce513Schristos@code{0}, sets @code{*@var{errmsg}} to an error message, and sets
131916dce513Schristos@code{*@var{err}} to an errno value or @code{0} if there is no
132016dce513Schristosrelevant errno.
132116dce513Schristos
132216dce513Schristos@end deftypefn
132316dce513Schristos
132416dce513Schristos@c simple-object.txh:27
132516dce513Schristos@deftypefn Extension {const char *} simple_object_find_sections @
132616dce513Schristos  (simple_object_read *@var{simple_object}, int (*@var{pfn}) (void *@var{data}, @
132716dce513Schristos  const char *@var{name}, off_t @var{offset}, off_t @var{length}), @
132816dce513Schristos  void *@var{data}, int *@var{err})
132916dce513Schristos
133016dce513SchristosThis function calls @var{pfn} for each section in @var{simple_object}.
133116dce513SchristosIt calls @var{pfn} with the section name, the offset within the file
133216dce513Schristosof the section contents, and the length of the section contents.  The
133316dce513Schristosoffset within the file is relative to the offset passed to
133416dce513Schristos@code{simple_object_open_read}.  The @var{data} argument to this
133516dce513Schristosfunction is passed along to @var{pfn}.
133616dce513Schristos
133716dce513SchristosIf @var{pfn} returns @code{0}, the loop over the sections stops and
133816dce513Schristos@code{simple_object_find_sections} returns.  If @var{pfn} returns some
133916dce513Schristosother value, the loop continues.
134016dce513Schristos
134116dce513SchristosOn success @code{simple_object_find_sections} returns.  On error it
134216dce513Schristosreturns an error string, and sets @code{*@var{err}} to an errno value
134316dce513Schristosor @code{0} if there is no relevant errno.
134416dce513Schristos
134516dce513Schristos@end deftypefn
134616dce513Schristos
134716dce513Schristos@c simple-object.txh:2
134816dce513Schristos@deftypefn Extension {simple_object_read *} simple_object_open_read @
134916dce513Schristos  (int @var{descriptor}, off_t @var{offset}, const char *{segment_name}, @
135016dce513Schristos  const char **@var{errmsg}, int *@var{err})
135116dce513Schristos
135216dce513SchristosOpens an object file for reading.  Creates and returns an
135316dce513Schristos@code{simple_object_read} pointer which may be passed to other
135416dce513Schristosfunctions to extract data from the object file.
135516dce513Schristos
135616dce513Schristos@var{descriptor} holds a file descriptor which permits reading.
135716dce513Schristos
135816dce513Schristos@var{offset} is the offset into the file; this will be @code{0} in the
135916dce513Schristosnormal case, but may be a different value when reading an object file
136016dce513Schristosin an archive file.
136116dce513Schristos
136216dce513Schristos@var{segment_name} is only used with the Mach-O file format used on
136316dce513SchristosDarwin aka Mac OS X.  It is required on that platform, and means to
136416dce513Schristosonly look at sections within the segment with that name.  The
136516dce513Schristosparameter is ignored on other systems.
136616dce513Schristos
136716dce513SchristosIf an error occurs, this functions returns @code{NULL} and sets
136816dce513Schristos@code{*@var{errmsg}} to an error string and sets @code{*@var{err}} to
136916dce513Schristosan errno value or @code{0} if there is no relevant errno.
137016dce513Schristos
137116dce513Schristos@end deftypefn
137216dce513Schristos
137316dce513Schristos@c simple-object.txh:107
137416dce513Schristos@deftypefn Extension {void} simple_object_release_attributes @
137516dce513Schristos  (simple_object_attributes *@var{attrs})
137616dce513Schristos
137716dce513SchristosRelease all resources associated with @var{attrs}.
137816dce513Schristos
137916dce513Schristos@end deftypefn
138016dce513Schristos
138116dce513Schristos@c simple-object.txh:73
138216dce513Schristos@deftypefn Extension {void} simple_object_release_read @
138316dce513Schristos  (simple_object_read *@var{simple_object})
138416dce513Schristos
138516dce513SchristosRelease all resources associated with @var{simple_object}.  This does
138616dce513Schristosnot close the file descriptor.
138716dce513Schristos
138816dce513Schristos@end deftypefn
138916dce513Schristos
139016dce513Schristos@c simple-object.txh:184
139116dce513Schristos@deftypefn Extension {void} simple_object_release_write @
139216dce513Schristos  (simple_object_write *@var{simple_object})
139316dce513Schristos
139416dce513SchristosRelease all resources associated with @var{simple_object}.
139516dce513Schristos
139616dce513Schristos@end deftypefn
139716dce513Schristos
139816dce513Schristos@c simple-object.txh:114
139916dce513Schristos@deftypefn Extension {simple_object_write *} simple_object_start_write @
140016dce513Schristos  (simple_object_attributes @var{attrs}, const char *@var{segment_name}, @
140116dce513Schristos  const char **@var{errmsg}, int *@var{err})
140216dce513Schristos
140316dce513SchristosStart creating a new object file using the object file format
140416dce513Schristosdescribed in @var{attrs}.  You must fetch attribute information from
140516dce513Schristosan existing object file before you can create a new one.  There is
140616dce513Schristoscurrently no support for creating an object file de novo.
140716dce513Schristos
140816dce513Schristos@var{segment_name} is only used with Mach-O as found on Darwin aka Mac
140916dce513SchristosOS X.  The parameter is required on that target.  It means that all
141016dce513Schristossections are created within the named segment.  It is ignored for
141116dce513Schristosother object file formats.
141216dce513Schristos
141316dce513SchristosOn error @code{simple_object_start_write} returns @code{NULL}, sets
141416dce513Schristos@code{*@var{ERRMSG}} to an error message, and sets @code{*@var{err}}
141516dce513Schristosto an errno value or @code{0} if there is no relevant errno.
141616dce513Schristos
141716dce513Schristos@end deftypefn
141816dce513Schristos
141916dce513Schristos@c simple-object.txh:153
142016dce513Schristos@deftypefn Extension {const char *} simple_object_write_add_data @
142116dce513Schristos  (simple_object_write *@var{simple_object}, @
142216dce513Schristos  simple_object_write_section *@var{section}, const void *@var{buffer}, @
142316dce513Schristos  size_t @var{size}, int @var{copy}, int *@var{err})
142416dce513Schristos
142516dce513SchristosAdd data @var{buffer}/@var{size} to @var{section} in
142616dce513Schristos@var{simple_object}.  If @var{copy} is non-zero, the data will be
142716dce513Schristoscopied into memory if necessary.  If @var{copy} is zero, @var{buffer}
142816dce513Schristosmust persist until @code{simple_object_write_to_file} is called.  is
142916dce513Schristosreleased.
143016dce513Schristos
143116dce513SchristosOn success this returns @code{NULL}.  On error this returns an error
143216dce513Schristosmessage, and sets @code{*@var{err}} to an errno value or 0 if there is
143316dce513Schristosno relevant erro.
143416dce513Schristos
143516dce513Schristos@end deftypefn
143616dce513Schristos
143716dce513Schristos@c simple-object.txh:134
143816dce513Schristos@deftypefn Extension {simple_object_write_section *} simple_object_write_create_section @
143916dce513Schristos  (simple_object_write *@var{simple_object}, const char *@var{name}, @
144016dce513Schristos  unsigned int @var{align}, const char **@var{errmsg}, int *@var{err})
144116dce513Schristos
144216dce513SchristosAdd a section to @var{simple_object}.  @var{name} is the name of the
144316dce513Schristosnew section.  @var{align} is the required alignment expressed as the
144416dce513Schristosnumber of required low-order 0 bits (e.g., 2 for alignment to a 32-bit
144516dce513Schristosboundary).
144616dce513Schristos
144716dce513SchristosThe section is created as containing data, readable, not writable, not
144816dce513Schristosexecutable, not loaded at runtime.  The section is not written to the
144916dce513Schristosfile until @code{simple_object_write_to_file} is called.
145016dce513Schristos
145116dce513SchristosOn error this returns @code{NULL}, sets @code{*@var{errmsg}} to an
145216dce513Schristoserror message, and sets @code{*@var{err}} to an errno value or
145316dce513Schristos@code{0} if there is no relevant errno.
145416dce513Schristos
145516dce513Schristos@end deftypefn
145616dce513Schristos
145716dce513Schristos@c simple-object.txh:170
145816dce513Schristos@deftypefn Extension {const char *} simple_object_write_to_file @
145916dce513Schristos  (simple_object_write *@var{simple_object}, int @var{descriptor}, int *@var{err})
146016dce513Schristos
146116dce513SchristosWrite the complete object file to @var{descriptor}, an open file
146216dce513Schristosdescriptor.  This writes out all the data accumulated by calls to
146316dce513Schristos@code{simple_object_write_create_section} and
146416dce513Schristos@var{simple_object_write_add_data}.
146516dce513Schristos
146616dce513SchristosThis returns @code{NULL} on success.  On error this returns an error
146716dce513Schristosmessage and sets @code{*@var{err}} to an errno value or @code{0} if
146816dce513Schristosthere is no relevant errno.
146916dce513Schristos
147016dce513Schristos@end deftypefn
147116dce513Schristos
147216dce513Schristos@c snprintf.c:28
147316dce513Schristos@deftypefn Supplemental int snprintf (char *@var{buf}, size_t @var{n}, @
147416dce513Schristos  const char *@var{format}, ...)
147516dce513Schristos
147616dce513SchristosThis function is similar to @code{sprintf}, but it will write to
147716dce513Schristos@var{buf} at most @code{@var{n}-1} bytes of text, followed by a
147816dce513Schristosterminating null byte, for a total of @var{n} bytes.
147916dce513SchristosOn error the return value is -1, otherwise it returns the number of
148016dce513Schristosbytes, not including the terminating null byte, that would have been
148116dce513Schristoswritten had @var{n} been sufficiently large, regardless of the actual
148216dce513Schristosvalue of @var{n}.  Note some pre-C99 system libraries do not implement
148316dce513Schristosthis correctly so users cannot generally rely on the return value if
148416dce513Schristosthe system version of this function is used.
148516dce513Schristos
148616dce513Schristos@end deftypefn
148716dce513Schristos
148816dce513Schristos@c spaces.c:22
148916dce513Schristos@deftypefn Extension char* spaces (int @var{count})
149016dce513Schristos
149116dce513SchristosReturns a pointer to a memory region filled with the specified
149216dce513Schristosnumber of spaces and null terminated.  The returned pointer is
149316dce513Schristosvalid until at least the next call.
149416dce513Schristos
149516dce513Schristos@end deftypefn
149616dce513Schristos
1497012573ebSchristos@c splay-tree.c:305
149816dce513Schristos@deftypefn Supplemental splay_tree splay_tree_new_with_typed_alloc @
149916dce513Schristos(splay_tree_compare_fn @var{compare_fn}, @
150016dce513Schristossplay_tree_delete_key_fn @var{delete_key_fn}, @
150116dce513Schristossplay_tree_delete_value_fn @var{delete_value_fn}, @
150216dce513Schristossplay_tree_allocate_fn @var{tree_allocate_fn}, @
150316dce513Schristossplay_tree_allocate_fn @var{node_allocate_fn}, @
150416dce513Schristossplay_tree_deallocate_fn @var{deallocate_fn}, @
150516dce513Schristosvoid * @var{allocate_data})
150616dce513Schristos
150716dce513SchristosThis function creates a splay tree that uses two different allocators
150816dce513Schristos@var{tree_allocate_fn} and @var{node_allocate_fn} to use for allocating the
150916dce513Schristostree itself and its nodes respectively.  This is useful when variables of
151016dce513Schristosdifferent types need to be allocated with different allocators.
151116dce513Schristos
151216dce513SchristosThe splay tree will use @var{compare_fn} to compare nodes,
151316dce513Schristos@var{delete_key_fn} to deallocate keys, and @var{delete_value_fn} to
1514012573ebSchristosdeallocate values.  Keys and values will be deallocated when the
1515012573ebSchristostree is deleted using splay_tree_delete or when a node is removed
1516012573ebSchristosusing splay_tree_remove.  splay_tree_insert will release the previously
1517012573ebSchristosinserted key and value using @var{delete_key_fn} and @var{delete_value_fn}
1518012573ebSchristosif the inserted key is already found in the tree.
151916dce513Schristos
152016dce513Schristos@end deftypefn
152116dce513Schristos
152216dce513Schristos@c stack-limit.c:28
152316dce513Schristos@deftypefn Extension void stack_limit_increase (unsigned long @var{pref})
152416dce513Schristos
152516dce513SchristosAttempt to increase stack size limit to @var{pref} bytes if possible.
152616dce513Schristos
152716dce513Schristos@end deftypefn
152816dce513Schristos
152916dce513Schristos@c stpcpy.c:23
153016dce513Schristos@deftypefn Supplemental char* stpcpy (char *@var{dst}, const char *@var{src})
153116dce513Schristos
153216dce513SchristosCopies the string @var{src} into @var{dst}.  Returns a pointer to
153316dce513Schristos@var{dst} + strlen(@var{src}).
153416dce513Schristos
153516dce513Schristos@end deftypefn
153616dce513Schristos
153716dce513Schristos@c stpncpy.c:23
153816dce513Schristos@deftypefn Supplemental char* stpncpy (char *@var{dst}, const char *@var{src}, @
153916dce513Schristos  size_t @var{len})
154016dce513Schristos
154116dce513SchristosCopies the string @var{src} into @var{dst}, copying exactly @var{len}
154216dce513Schristosand padding with zeros if necessary.  If @var{len} < strlen(@var{src})
154316dce513Schristosthen return @var{dst} + @var{len}, otherwise returns @var{dst} +
154416dce513Schristosstrlen(@var{src}).
154516dce513Schristos
154616dce513Schristos@end deftypefn
154716dce513Schristos
154816dce513Schristos@c strcasecmp.c:15
154916dce513Schristos@deftypefn Supplemental int strcasecmp (const char *@var{s1}, const char *@var{s2})
155016dce513Schristos
155116dce513SchristosA case-insensitive @code{strcmp}.
155216dce513Schristos
155316dce513Schristos@end deftypefn
155416dce513Schristos
155516dce513Schristos@c strchr.c:6
155616dce513Schristos@deftypefn Supplemental char* strchr (const char *@var{s}, int @var{c})
155716dce513Schristos
155816dce513SchristosReturns a pointer to the first occurrence of the character @var{c} in
155916dce513Schristosthe string @var{s}, or @code{NULL} if not found.  If @var{c} is itself the
156016dce513Schristosnull character, the results are undefined.
156116dce513Schristos
156216dce513Schristos@end deftypefn
156316dce513Schristos
156416dce513Schristos@c strdup.c:3
156516dce513Schristos@deftypefn Supplemental char* strdup (const char *@var{s})
156616dce513Schristos
156716dce513SchristosReturns a pointer to a copy of @var{s} in memory obtained from
156816dce513Schristos@code{malloc}, or @code{NULL} if insufficient memory was available.
156916dce513Schristos
157016dce513Schristos@end deftypefn
157116dce513Schristos
1572012573ebSchristos@c strerror.c:675
157316dce513Schristos@deftypefn Replacement {const char*} strerrno (int @var{errnum})
157416dce513Schristos
157516dce513SchristosGiven an error number returned from a system call (typically returned
157616dce513Schristosin @code{errno}), returns a pointer to a string containing the
157716dce513Schristossymbolic name of that error number, as found in @code{<errno.h>}.
157816dce513Schristos
157916dce513SchristosIf the supplied error number is within the valid range of indices for
158016dce513Schristossymbolic names, but no name is available for the particular error
158116dce513Schristosnumber, then returns the string @samp{Error @var{num}}, where @var{num}
158216dce513Schristosis the error number.
158316dce513Schristos
158416dce513SchristosIf the supplied error number is not within the range of valid
158516dce513Schristosindices, then returns @code{NULL}.
158616dce513Schristos
158716dce513SchristosThe contents of the location pointed to are only guaranteed to be
158816dce513Schristosvalid until the next call to @code{strerrno}.
158916dce513Schristos
159016dce513Schristos@end deftypefn
159116dce513Schristos
1592012573ebSchristos@c strerror.c:608
159316dce513Schristos@deftypefn Supplemental char* strerror (int @var{errnoval})
159416dce513Schristos
159516dce513SchristosMaps an @code{errno} number to an error message string, the contents
159616dce513Schristosof which are implementation defined.  On systems which have the
159716dce513Schristosexternal variables @code{sys_nerr} and @code{sys_errlist}, these
159816dce513Schristosstrings will be the same as the ones used by @code{perror}.
159916dce513Schristos
160016dce513SchristosIf the supplied error number is within the valid range of indices for
160116dce513Schristosthe @code{sys_errlist}, but no message is available for the particular
160216dce513Schristoserror number, then returns the string @samp{Error @var{num}}, where
160316dce513Schristos@var{num} is the error number.
160416dce513Schristos
160516dce513SchristosIf the supplied error number is not a valid index into
160616dce513Schristos@code{sys_errlist}, returns @code{NULL}.
160716dce513Schristos
160816dce513SchristosThe returned string is only guaranteed to be valid only until the
160916dce513Schristosnext call to @code{strerror}.
161016dce513Schristos
161116dce513Schristos@end deftypefn
161216dce513Schristos
161316dce513Schristos@c strncasecmp.c:15
161416dce513Schristos@deftypefn Supplemental int strncasecmp (const char *@var{s1}, const char *@var{s2})
161516dce513Schristos
161616dce513SchristosA case-insensitive @code{strncmp}.
161716dce513Schristos
161816dce513Schristos@end deftypefn
161916dce513Schristos
162016dce513Schristos@c strncmp.c:6
162116dce513Schristos@deftypefn Supplemental int strncmp (const char *@var{s1}, @
162216dce513Schristos  const char *@var{s2}, size_t @var{n})
162316dce513Schristos
162416dce513SchristosCompares the first @var{n} bytes of two strings, returning a value as
162516dce513Schristos@code{strcmp}.
162616dce513Schristos
162716dce513Schristos@end deftypefn
162816dce513Schristos
162916dce513Schristos@c strndup.c:23
163016dce513Schristos@deftypefn Extension char* strndup (const char *@var{s}, size_t @var{n})
163116dce513Schristos
163216dce513SchristosReturns a pointer to a copy of @var{s} with at most @var{n} characters
163316dce513Schristosin memory obtained from @code{malloc}, or @code{NULL} if insufficient
163416dce513Schristosmemory was available.  The result is always NUL terminated.
163516dce513Schristos
163616dce513Schristos@end deftypefn
163716dce513Schristos
163816dce513Schristos@c strnlen.c:6
163916dce513Schristos@deftypefn Supplemental size_t strnlen (const char *@var{s}, size_t @var{maxlen})
164016dce513Schristos
164116dce513SchristosReturns the length of @var{s}, as with @code{strlen}, but never looks
164216dce513Schristospast the first @var{maxlen} characters in the string.  If there is no
164316dce513Schristos'\0' character in the first @var{maxlen} characters, returns
164416dce513Schristos@var{maxlen}.
164516dce513Schristos
164616dce513Schristos@end deftypefn
164716dce513Schristos
164816dce513Schristos@c strrchr.c:6
164916dce513Schristos@deftypefn Supplemental char* strrchr (const char *@var{s}, int @var{c})
165016dce513Schristos
165116dce513SchristosReturns a pointer to the last occurrence of the character @var{c} in
165216dce513Schristosthe string @var{s}, or @code{NULL} if not found.  If @var{c} is itself the
165316dce513Schristosnull character, the results are undefined.
165416dce513Schristos
165516dce513Schristos@end deftypefn
165616dce513Schristos
165716dce513Schristos@c strsignal.c:383
165816dce513Schristos@deftypefn Supplemental {const char *} strsignal (int @var{signo})
165916dce513Schristos
166016dce513SchristosMaps an signal number to an signal message string, the contents of
166116dce513Schristoswhich are implementation defined.  On systems which have the external
166216dce513Schristosvariable @code{sys_siglist}, these strings will be the same as the
166316dce513Schristosones used by @code{psignal()}.
166416dce513Schristos
166516dce513SchristosIf the supplied signal number is within the valid range of indices for
166616dce513Schristosthe @code{sys_siglist}, but no message is available for the particular
166716dce513Schristossignal number, then returns the string @samp{Signal @var{num}}, where
166816dce513Schristos@var{num} is the signal number.
166916dce513Schristos
167016dce513SchristosIf the supplied signal number is not a valid index into
167116dce513Schristos@code{sys_siglist}, returns @code{NULL}.
167216dce513Schristos
167316dce513SchristosThe returned string is only guaranteed to be valid only until the next
167416dce513Schristoscall to @code{strsignal}.
167516dce513Schristos
167616dce513Schristos@end deftypefn
167716dce513Schristos
167816dce513Schristos@c strsignal.c:448
167916dce513Schristos@deftypefn Extension {const char*} strsigno (int @var{signo})
168016dce513Schristos
168116dce513SchristosGiven an signal number, returns a pointer to a string containing the
168216dce513Schristossymbolic name of that signal number, as found in @code{<signal.h>}.
168316dce513Schristos
168416dce513SchristosIf the supplied signal number is within the valid range of indices for
168516dce513Schristossymbolic names, but no name is available for the particular signal
168616dce513Schristosnumber, then returns the string @samp{Signal @var{num}}, where
168716dce513Schristos@var{num} is the signal number.
168816dce513Schristos
168916dce513SchristosIf the supplied signal number is not within the range of valid
169016dce513Schristosindices, then returns @code{NULL}.
169116dce513Schristos
169216dce513SchristosThe contents of the location pointed to are only guaranteed to be
169316dce513Schristosvalid until the next call to @code{strsigno}.
169416dce513Schristos
169516dce513Schristos@end deftypefn
169616dce513Schristos
169716dce513Schristos@c strstr.c:6
169816dce513Schristos@deftypefn Supplemental char* strstr (const char *@var{string}, const char *@var{sub})
169916dce513Schristos
170016dce513SchristosThis function searches for the substring @var{sub} in the string
170116dce513Schristos@var{string}, not including the terminating null characters.  A pointer
170216dce513Schristosto the first occurrence of @var{sub} is returned, or @code{NULL} if the
170316dce513Schristossubstring is absent.  If @var{sub} points to a string with zero
170416dce513Schristoslength, the function returns @var{string}.
170516dce513Schristos
170616dce513Schristos@end deftypefn
170716dce513Schristos
170816dce513Schristos@c strtod.c:27
170916dce513Schristos@deftypefn Supplemental double strtod (const char *@var{string}, @
171016dce513Schristos  char **@var{endptr})
171116dce513Schristos
171216dce513SchristosThis ISO C function converts the initial portion of @var{string} to a
171316dce513Schristos@code{double}.  If @var{endptr} is not @code{NULL}, a pointer to the
171416dce513Schristoscharacter after the last character used in the conversion is stored in
171516dce513Schristosthe location referenced by @var{endptr}.  If no conversion is
171616dce513Schristosperformed, zero is returned and the value of @var{string} is stored in
171716dce513Schristosthe location referenced by @var{endptr}.
171816dce513Schristos
171916dce513Schristos@end deftypefn
172016dce513Schristos
1721012573ebSchristos@c strerror.c:734
172216dce513Schristos@deftypefn Extension int strtoerrno (const char *@var{name})
172316dce513Schristos
172416dce513SchristosGiven the symbolic name of a error number (e.g., @code{EACCES}), map it
172516dce513Schristosto an errno value.  If no translation is found, returns 0.
172616dce513Schristos
172716dce513Schristos@end deftypefn
172816dce513Schristos
172916dce513Schristos@c strtol.c:33
173016dce513Schristos@deftypefn Supplemental {long int} strtol (const char *@var{string}, @
173116dce513Schristos  char **@var{endptr}, int @var{base})
173216dce513Schristos@deftypefnx Supplemental {unsigned long int} strtoul (const char *@var{string}, @
173316dce513Schristos  char **@var{endptr}, int @var{base})
173416dce513Schristos
173516dce513SchristosThe @code{strtol} function converts the string in @var{string} to a
173616dce513Schristoslong integer value according to the given @var{base}, which must be
173716dce513Schristosbetween 2 and 36 inclusive, or be the special value 0.  If @var{base}
173816dce513Schristosis 0, @code{strtol} will look for the prefixes @code{0} and @code{0x}
173916dce513Schristosto indicate bases 8 and 16, respectively, else default to base 10.
174016dce513SchristosWhen the base is 16 (either explicitly or implicitly), a prefix of
174116dce513Schristos@code{0x} is allowed.  The handling of @var{endptr} is as that of
174216dce513Schristos@code{strtod} above.  The @code{strtoul} function is the same, except
174316dce513Schristosthat the converted value is unsigned.
174416dce513Schristos
174516dce513Schristos@end deftypefn
174616dce513Schristos
174716dce513Schristos@c strtoll.c:33
174816dce513Schristos@deftypefn Supplemental {long long int} strtoll (const char *@var{string}, @
174916dce513Schristos  char **@var{endptr}, int @var{base})
175016dce513Schristos@deftypefnx Supplemental {unsigned long long int} strtoul (@
175116dce513Schristos  const char *@var{string}, char **@var{endptr}, int @var{base})
175216dce513Schristos
175316dce513SchristosThe @code{strtoll} function converts the string in @var{string} to a
175416dce513Schristoslong long integer value according to the given @var{base}, which must be
175516dce513Schristosbetween 2 and 36 inclusive, or be the special value 0.  If @var{base}
175616dce513Schristosis 0, @code{strtoll} will look for the prefixes @code{0} and @code{0x}
175716dce513Schristosto indicate bases 8 and 16, respectively, else default to base 10.
175816dce513SchristosWhen the base is 16 (either explicitly or implicitly), a prefix of
175916dce513Schristos@code{0x} is allowed.  The handling of @var{endptr} is as that of
176016dce513Schristos@code{strtod} above.  The @code{strtoull} function is the same, except
176116dce513Schristosthat the converted value is unsigned.
176216dce513Schristos
176316dce513Schristos@end deftypefn
176416dce513Schristos
176516dce513Schristos@c strsignal.c:502
176616dce513Schristos@deftypefn Extension int strtosigno (const char *@var{name})
176716dce513Schristos
176816dce513SchristosGiven the symbolic name of a signal, map it to a signal number.  If no
176916dce513Schristostranslation is found, returns 0.
177016dce513Schristos
177116dce513Schristos@end deftypefn
177216dce513Schristos
177316dce513Schristos@c strverscmp.c:25
177416dce513Schristos@deftypefun int strverscmp (const char *@var{s1}, const char *@var{s2})
177516dce513SchristosThe @code{strverscmp} function compares the string @var{s1} against
177616dce513Schristos@var{s2}, considering them as holding indices/version numbers.  Return
177716dce513Schristosvalue follows the same conventions as found in the @code{strverscmp}
177816dce513Schristosfunction.  In fact, if @var{s1} and @var{s2} contain no digits,
177916dce513Schristos@code{strverscmp} behaves like @code{strcmp}.
178016dce513Schristos
178116dce513SchristosBasically, we compare strings normally (character by character), until
178216dce513Schristoswe find a digit in each string - then we enter a special comparison
178316dce513Schristosmode, where each sequence of digits is taken as a whole.  If we reach the
178416dce513Schristosend of these two parts without noticing a difference, we return to the
178516dce513Schristosstandard comparison mode.  There are two types of numeric parts:
178616dce513Schristos"integral" and "fractional" (those  begin with a '0'). The types
178716dce513Schristosof the numeric parts affect the way we sort them:
178816dce513Schristos
178916dce513Schristos@itemize @bullet
179016dce513Schristos@item
179116dce513Schristosintegral/integral: we compare values as you would expect.
179216dce513Schristos
179316dce513Schristos@item
179416dce513Schristosfractional/integral: the fractional part is less than the integral one.
179516dce513SchristosAgain, no surprise.
179616dce513Schristos
179716dce513Schristos@item
179816dce513Schristosfractional/fractional: the things become a bit more complex.
179916dce513SchristosIf the common prefix contains only leading zeroes, the longest part is less
180016dce513Schristosthan the other one; else the comparison behaves normally.
180116dce513Schristos@end itemize
180216dce513Schristos
180316dce513Schristos@smallexample
180416dce513Schristosstrverscmp ("no digit", "no digit")
180516dce513Schristos    @result{} 0    // @r{same behavior as strcmp.}
180616dce513Schristosstrverscmp ("item#99", "item#100")
180716dce513Schristos    @result{} <0   // @r{same prefix, but 99 < 100.}
180816dce513Schristosstrverscmp ("alpha1", "alpha001")
180916dce513Schristos    @result{} >0   // @r{fractional part inferior to integral one.}
181016dce513Schristosstrverscmp ("part1_f012", "part1_f01")
181116dce513Schristos    @result{} >0   // @r{two fractional parts.}
181216dce513Schristosstrverscmp ("foo.009", "foo.0")
181316dce513Schristos    @result{} <0   // @r{idem, but with leading zeroes only.}
181416dce513Schristos@end smallexample
181516dce513Schristos
181616dce513SchristosThis function is especially useful when dealing with filename sorting,
181716dce513Schristosbecause filenames frequently hold indices/version numbers.
181816dce513Schristos@end deftypefun
181916dce513Schristos
182016dce513Schristos@c timeval-utils.c:43
182116dce513Schristos@deftypefn Extension void timeval_add (struct timeval *@var{a}, @
182216dce513Schristos  struct timeval *@var{b}, struct timeval *@var{result})
182316dce513Schristos
182416dce513SchristosAdds @var{a} to @var{b} and stores the result in @var{result}.
182516dce513Schristos
182616dce513Schristos@end deftypefn
182716dce513Schristos
182816dce513Schristos@c timeval-utils.c:67
182916dce513Schristos@deftypefn Extension void timeval_sub (struct timeval *@var{a}, @
183016dce513Schristos  struct timeval *@var{b}, struct timeval *@var{result})
183116dce513Schristos
183216dce513SchristosSubtracts @var{b} from @var{a} and stores the result in @var{result}.
183316dce513Schristos
183416dce513Schristos@end deftypefn
183516dce513Schristos
183616dce513Schristos@c tmpnam.c:3
183716dce513Schristos@deftypefn Supplemental char* tmpnam (char *@var{s})
183816dce513Schristos
183916dce513SchristosThis function attempts to create a name for a temporary file, which
184016dce513Schristoswill be a valid file name yet not exist when @code{tmpnam} checks for
184116dce513Schristosit.  @var{s} must point to a buffer of at least @code{L_tmpnam} bytes,
184216dce513Schristosor be @code{NULL}.  Use of this function creates a security risk, and it must
184316dce513Schristosnot be used in new projects.  Use @code{mkstemp} instead.
184416dce513Schristos
184516dce513Schristos@end deftypefn
184616dce513Schristos
184716dce513Schristos@c unlink-if-ordinary.c:27
184816dce513Schristos@deftypefn Supplemental int unlink_if_ordinary (const char*)
184916dce513Schristos
185016dce513SchristosUnlinks the named file, unless it is special (e.g. a device file).
185116dce513SchristosReturns 0 when the file was unlinked, a negative value (and errno set) when
185216dce513Schristosthere was an error deleting the file, and a positive value if no attempt
185316dce513Schristoswas made to unlink the file because it is special.
185416dce513Schristos
185516dce513Schristos@end deftypefn
185616dce513Schristos
185716dce513Schristos@c fopen_unlocked.c:31
185816dce513Schristos@deftypefn Extension void unlock_std_streams (void)
185916dce513Schristos
186016dce513SchristosIf the OS supports it, ensure that the standard I/O streams,
186116dce513Schristos@code{stdin}, @code{stdout} and @code{stderr} are setup to avoid any
186216dce513Schristosmulti-threaded locking.  Otherwise do nothing.
186316dce513Schristos
186416dce513Schristos@end deftypefn
186516dce513Schristos
186616dce513Schristos@c fopen_unlocked.c:23
186716dce513Schristos@deftypefn Extension void unlock_stream (FILE * @var{stream})
186816dce513Schristos
186916dce513SchristosIf the OS supports it, ensure that the supplied stream is setup to
187016dce513Schristosavoid any multi-threaded locking.  Otherwise leave the @code{FILE}
187116dce513Schristospointer unchanged.  If the @var{stream} is @code{NULL} do nothing.
187216dce513Schristos
187316dce513Schristos@end deftypefn
187416dce513Schristos
187516dce513Schristos@c vasprintf.c:47
187616dce513Schristos@deftypefn Extension int vasprintf (char **@var{resptr}, @
187716dce513Schristos  const char *@var{format}, va_list @var{args})
187816dce513Schristos
187916dce513SchristosLike @code{vsprintf}, but instead of passing a pointer to a buffer,
188016dce513Schristosyou pass a pointer to a pointer.  This function will compute the size
188116dce513Schristosof the buffer needed, allocate memory with @code{malloc}, and store a
188216dce513Schristospointer to the allocated memory in @code{*@var{resptr}}.  The value
188316dce513Schristosreturned is the same as @code{vsprintf} would return.  If memory could
188416dce513Schristosnot be allocated, minus one is returned and @code{NULL} is stored in
188516dce513Schristos@code{*@var{resptr}}.
188616dce513Schristos
188716dce513Schristos@end deftypefn
188816dce513Schristos
188916dce513Schristos@c vfork.c:6
189016dce513Schristos@deftypefn Supplemental int vfork (void)
189116dce513Schristos
189216dce513SchristosEmulates @code{vfork} by calling @code{fork} and returning its value.
189316dce513Schristos
189416dce513Schristos@end deftypefn
189516dce513Schristos
189616dce513Schristos@c vprintf.c:3
189716dce513Schristos@deftypefn Supplemental int vprintf (const char *@var{format}, va_list @var{ap})
189816dce513Schristos@deftypefnx Supplemental int vfprintf (FILE *@var{stream}, @
189916dce513Schristos  const char *@var{format}, va_list @var{ap})
190016dce513Schristos@deftypefnx Supplemental int vsprintf (char *@var{str}, @
190116dce513Schristos  const char *@var{format}, va_list @var{ap})
190216dce513Schristos
190316dce513SchristosThese functions are the same as @code{printf}, @code{fprintf}, and
190416dce513Schristos@code{sprintf}, respectively, except that they are called with a
190516dce513Schristos@code{va_list} instead of a variable number of arguments.  Note that
190616dce513Schristosthey do not call @code{va_end}; this is the application's
190716dce513Schristosresponsibility.  In @libib{} they are implemented in terms of the
190816dce513Schristosnonstandard but common function @code{_doprnt}.
190916dce513Schristos
191016dce513Schristos@end deftypefn
191116dce513Schristos
191216dce513Schristos@c vsnprintf.c:28
191316dce513Schristos@deftypefn Supplemental int vsnprintf (char *@var{buf}, size_t @var{n}, @
191416dce513Schristos  const char *@var{format}, va_list @var{ap})
191516dce513Schristos
191616dce513SchristosThis function is similar to @code{vsprintf}, but it will write to
191716dce513Schristos@var{buf} at most @code{@var{n}-1} bytes of text, followed by a
191816dce513Schristosterminating null byte, for a total of @var{n} bytes.  On error the
191916dce513Schristosreturn value is -1, otherwise it returns the number of characters that
192016dce513Schristoswould have been printed had @var{n} been sufficiently large,
192116dce513Schristosregardless of the actual value of @var{n}.  Note some pre-C99 system
192216dce513Schristoslibraries do not implement this correctly so users cannot generally
192316dce513Schristosrely on the return value if the system version of this function is
192416dce513Schristosused.
192516dce513Schristos
192616dce513Schristos@end deftypefn
192716dce513Schristos
192816dce513Schristos@c waitpid.c:3
192916dce513Schristos@deftypefn Supplemental int waitpid (int @var{pid}, int *@var{status}, int)
193016dce513Schristos
193116dce513SchristosThis is a wrapper around the @code{wait} function.  Any ``special''
193216dce513Schristosvalues of @var{pid} depend on your implementation of @code{wait}, as
193316dce513Schristosdoes the return value.  The third argument is unused in @libib{}.
193416dce513Schristos
193516dce513Schristos@end deftypefn
193616dce513Schristos
1937012573ebSchristos@c argv.c:289
193816dce513Schristos@deftypefn Extension int writeargv (char * const *@var{argv}, FILE *@var{file})
193916dce513Schristos
194016dce513SchristosWrite each member of ARGV, handling all necessary quoting, to the file
194116dce513Schristosnamed by FILE, separated by whitespace.  Return 0 on success, non-zero
194216dce513Schristosif an error occurred while writing to FILE.
194316dce513Schristos
194416dce513Schristos@end deftypefn
194516dce513Schristos
194616dce513Schristos@c xasprintf.c:31
194716dce513Schristos@deftypefn Replacement char* xasprintf (const char *@var{format}, ...)
194816dce513Schristos
194916dce513SchristosPrint to allocated string without fail.  If @code{xasprintf} fails,
195016dce513Schristosthis will print a message to @code{stderr} (using the name set by
195116dce513Schristos@code{xmalloc_set_program_name}, if any) and then call @code{xexit}.
195216dce513Schristos
195316dce513Schristos@end deftypefn
195416dce513Schristos
195516dce513Schristos@c xatexit.c:11
195616dce513Schristos@deftypefun int xatexit (void (*@var{fn}) (void))
195716dce513Schristos
195816dce513SchristosBehaves as the standard @code{atexit} function, but with no limit on
195916dce513Schristosthe number of registered functions.  Returns 0 on success, or @minus{}1 on
196016dce513Schristosfailure.  If you use @code{xatexit} to register functions, you must use
196116dce513Schristos@code{xexit} to terminate your program.
196216dce513Schristos
196316dce513Schristos@end deftypefun
196416dce513Schristos
196516dce513Schristos@c xmalloc.c:38
196616dce513Schristos@deftypefn Replacement void* xcalloc (size_t @var{nelem}, size_t @var{elsize})
196716dce513Schristos
196816dce513SchristosAllocate memory without fail, and set it to zero.  This routine functions
196916dce513Schristoslike @code{calloc}, but will behave the same as @code{xmalloc} if memory
197016dce513Schristoscannot be found.
197116dce513Schristos
197216dce513Schristos@end deftypefn
197316dce513Schristos
197416dce513Schristos@c xexit.c:22
197516dce513Schristos@deftypefn Replacement void xexit (int @var{code})
197616dce513Schristos
197716dce513SchristosTerminates the program.  If any functions have been registered with
197816dce513Schristosthe @code{xatexit} replacement function, they will be called first.
197916dce513SchristosTermination is handled via the system's normal @code{exit} call.
198016dce513Schristos
198116dce513Schristos@end deftypefn
198216dce513Schristos
198316dce513Schristos@c xmalloc.c:22
198416dce513Schristos@deftypefn Replacement void* xmalloc (size_t)
198516dce513Schristos
198616dce513SchristosAllocate memory without fail.  If @code{malloc} fails, this will print
198716dce513Schristosa message to @code{stderr} (using the name set by
198816dce513Schristos@code{xmalloc_set_program_name},
198916dce513Schristosif any) and then call @code{xexit}.  Note that it is therefore safe for
199016dce513Schristosa program to contain @code{#define malloc xmalloc} in its source.
199116dce513Schristos
199216dce513Schristos@end deftypefn
199316dce513Schristos
199416dce513Schristos@c xmalloc.c:53
199516dce513Schristos@deftypefn Replacement void xmalloc_failed (size_t)
199616dce513Schristos
199716dce513SchristosThis function is not meant to be called by client code, and is listed
199816dce513Schristoshere for completeness only.  If any of the allocation routines fail, this
199916dce513Schristosfunction will be called to print an error message and terminate execution.
200016dce513Schristos
200116dce513Schristos@end deftypefn
200216dce513Schristos
200316dce513Schristos@c xmalloc.c:46
200416dce513Schristos@deftypefn Replacement void xmalloc_set_program_name (const char *@var{name})
200516dce513Schristos
200616dce513SchristosYou can use this to set the name of the program used by
200716dce513Schristos@code{xmalloc_failed} when printing a failure message.
200816dce513Schristos
200916dce513Schristos@end deftypefn
201016dce513Schristos
201116dce513Schristos@c xmemdup.c:7
201216dce513Schristos@deftypefn Replacement void* xmemdup (void *@var{input}, @
201316dce513Schristos  size_t @var{copy_size}, size_t @var{alloc_size})
201416dce513Schristos
201516dce513SchristosDuplicates a region of memory without fail.  First, @var{alloc_size} bytes
201616dce513Schristosare allocated, then @var{copy_size} bytes from @var{input} are copied into
201716dce513Schristosit, and the new memory is returned.  If fewer bytes are copied than were
201816dce513Schristosallocated, the remaining memory is zeroed.
201916dce513Schristos
202016dce513Schristos@end deftypefn
202116dce513Schristos
202216dce513Schristos@c xmalloc.c:32
202316dce513Schristos@deftypefn Replacement void* xrealloc (void *@var{ptr}, size_t @var{size})
202416dce513SchristosReallocate memory without fail.  This routine functions like @code{realloc},
202516dce513Schristosbut will behave the same as @code{xmalloc} if memory cannot be found.
202616dce513Schristos
202716dce513Schristos@end deftypefn
202816dce513Schristos
202916dce513Schristos@c xstrdup.c:7
203016dce513Schristos@deftypefn Replacement char* xstrdup (const char *@var{s})
203116dce513Schristos
203216dce513SchristosDuplicates a character string without fail, using @code{xmalloc} to
203316dce513Schristosobtain memory.
203416dce513Schristos
203516dce513Schristos@end deftypefn
203616dce513Schristos
203716dce513Schristos@c xstrerror.c:7
203816dce513Schristos@deftypefn Replacement char* xstrerror (int @var{errnum})
203916dce513Schristos
204016dce513SchristosBehaves exactly like the standard @code{strerror} function, but
204116dce513Schristoswill never return a @code{NULL} pointer.
204216dce513Schristos
204316dce513Schristos@end deftypefn
204416dce513Schristos
204516dce513Schristos@c xstrndup.c:23
204616dce513Schristos@deftypefn Replacement char* xstrndup (const char *@var{s}, size_t @var{n})
204716dce513Schristos
204816dce513SchristosReturns a pointer to a copy of @var{s} with at most @var{n} characters
204916dce513Schristoswithout fail, using @code{xmalloc} to obtain memory.  The result is
205016dce513Schristosalways NUL terminated.
205116dce513Schristos
205216dce513Schristos@end deftypefn
205316dce513Schristos
205416dce513Schristos@c xvasprintf.c:38
205516dce513Schristos@deftypefn Replacement char* xvasprintf (const char *@var{format}, va_list @var{args})
205616dce513Schristos
205716dce513SchristosPrint to allocated string without fail.  If @code{xvasprintf} fails,
205816dce513Schristosthis will print a message to @code{stderr} (using the name set by
205916dce513Schristos@code{xmalloc_set_program_name}, if any) and then call @code{xexit}.
206016dce513Schristos
206116dce513Schristos@end deftypefn
206216dce513Schristos
206316dce513Schristos
2064