]> Git Repo - binutils.git/blame - libiberty/functions.texi
2003-05-15 Andrew Cagney <[email protected]>
[binutils.git] / libiberty / functions.texi
CommitLineData
39423523
DD
1@c Automatically generated from *.c and others (the comments before
2@c each entry tell you which file and where in that file). DO NOT EDIT!
3@c Edit the *.c files, configure with --enable-maintainer-mode,
4@c and let gather-docs build you a new copy.
5
6@c alloca.c:26
99b58139 7@deftypefn Replacement void* alloca (size_t @var{size})
39423523
DD
8
9This function allocates memory which will be automatically reclaimed
10after the procedure exits. The @libib{} implementation does not free
11the memory immediately but will do so eventually during subsequent
12calls to this function. Memory is allocated using @code{xmalloc} under
13normal circumstances.
14
15The header file @file{alloca-conf.h} can be used in conjunction with the
16GNU Autoconf test @code{AC_FUNC_ALLOCA} to test for and properly make
17available this function. The @code{AC_FUNC_ALLOCA} test requires that
18client code use a block of preprocessor code to be safe (see the Autoconf
19manual for more); this header incorporates that logic and more, including
99b58139 20the possibility of a GCC built-in function.
39423523
DD
21
22@end deftypefn
23
ba19b94f 24@c asprintf.c:33
5d852400 25@deftypefn Extension int asprintf (char **@var{resptr}, const char *@var{format}, ...)
ba19b94f
DD
26
27Like @code{sprintf}, but instead of passing a pointer to a buffer, you
28pass a pointer to a pointer. This function will compute the size of
29the buffer needed, allocate memory with @code{malloc}, and store a
30pointer to the allocated memory in @code{*@var{resptr}}. The value
31returned is the same as @code{sprintf} would return. If memory could
32not be allocated, zero is returned and @code{NULL} is stored in
33@code{*@var{resptr}}.
34
35@end deftypefn
36
39423523
DD
37@c atexit.c:6
38@deftypefn Supplemental int atexit (void (*@var{f})())
39
40Causes function @var{f} to be called at exit. Returns 0.
41
42@end deftypefn
43
44@c basename.c:6
45@deftypefn Supplemental char* basename (const char *@var{name})
46
47Returns a pointer to the last component of pathname @var{name}.
48Behavior is undefined if the pathname ends in a directory separator.
49
50@end deftypefn
51
52@c bcmp.c:6
53@deftypefn Supplemental int bcmp (char *@var{x}, char *@var{y}, int @var{count})
54
55Compares the first @var{count} bytes of two areas of memory. Returns
56056af5
DD
56zero if they are the same, nonzero otherwise. Returns zero if
57@var{count} is zero. A nonzero result only indicates a difference,
39423523
DD
58it does not indicate any sorting order (say, by having a positive
59result mean @var{x} sorts before @var{y}).
60
61@end deftypefn
62
63@c bcopy.c:3
64@deftypefn Supplemental void bcopy (char *@var{in}, char *@var{out}, int @var{length})
65
66Copies @var{length} bytes from memory region @var{in} to region
67@var{out}. The use of @code{bcopy} is deprecated in new programs.
68
69@end deftypefn
70
71@c bsearch.c:33
72@deftypefn Supplemental void* bsearch (const void *@var{key}, const void *@var{base}, size_t @var{nmemb}, size_t @var{size}, int (*@var{compar})(const void *, const void *))
73
74Performs a search over an array of @var{nmemb} elements pointed to by
75@var{base} for a member that matches the object pointed to by @var{key}.
76The size of each member is specified by @var{size}. The array contents
77should be sorted in ascending order according to the @var{compar}
78comparison function. This routine should take two arguments pointing to
79the @var{key} and to an array member, in that order, and should return an
80integer less than, equal to, or greater than zero if the @var{key} object
fa9f0e33 81is respectively less than, matching, or greater than the array member.
39423523
DD
82
83@end deftypefn
84
ba19b94f
DD
85@c argv.c:139
86@deftypefn Extension char** buildargv (char *@var{sp})
87
88Given a pointer to a string, parse the string extracting fields
89separated by whitespace and optionally enclosed within either single
90or double quotes (which are stripped off), and build a vector of
91pointers to copies of the string for each field. The input string
92remains unchanged. The last element of the vector is followed by a
93@code{NULL} element.
94
95All of the memory for the pointer array and copies of the string
96is obtained from @code{malloc}. All of the memory can be returned to the
97system with the single function call @code{freeargv}, which takes the
98returned result of @code{buildargv}, as it's argument.
99
5d852400 100Returns a pointer to the argument vector if successful. Returns
ba19b94f
DD
101@code{NULL} if @var{sp} is @code{NULL} or if there is insufficient
102memory to complete building the argument vector.
103
104If the input is a null string (as opposed to a @code{NULL} pointer),
105then buildarg returns an argument vector that has one arg, a null
106string.
107
108@end deftypefn
109
39423523
DD
110@c bzero.c:6
111@deftypefn Supplemental void bzero (char *@var{mem}, int @var{count})
112
fa9f0e33 113Zeros @var{count} bytes starting at @var{mem}. Use of this function
39423523
DD
114is deprecated in favor of @code{memset}.
115
116@end deftypefn
117
118@c calloc.c:6
119@deftypefn Supplemental void* calloc (size_t @var{nelem}, size_t @var{elsize})
120
121Uses @code{malloc} to allocate storage for @var{nelem} objects of
122@var{elsize} bytes each, then zeros the memory.
123
124@end deftypefn
125
ba19b94f 126@c choose-temp.c:42
5d852400 127@deftypefn Extension char* choose_temp_base (void)
ba19b94f
DD
128
129Return a prefix for temporary file names or @code{NULL} if unable to
130find one. The current directory is chosen if all else fails so the
131program is exited if a temporary directory can't be found (@code{mktemp}
132fails). The buffer for the result is obtained with @code{xmalloc}.
133
134This function is provided for backwards compatability only. Its use is
135not recommended.
136
137@end deftypefn
138
139@c make-temp-file.c:88
140@deftypefn Replacement char* choose_tmpdir ()
141
142Returns a pointer to a directory path suitable for creating temporary
143files in.
144
145@end deftypefn
146
39423523 147@c clock.c:27
99b58139 148@deftypefn Supplemental long clock (void)
39423523
DD
149
150Returns an approximation of the CPU time used by the process as a
151@code{clock_t}; divide this number by @samp{CLOCKS_PER_SEC} to get the
152number of seconds used.
153
154@end deftypefn
155
ba19b94f 156@c concat.c:24
5d852400 157@deftypefn Extension char* concat (const char *@var{s1}, const char *@var{s2}, @dots{}, @code{NULL})
ba19b94f
DD
158
159Concatenate zero or more of strings and return the result in freshly
5d852400 160@code{xmalloc}ed memory. Returns @code{NULL} if insufficient memory is
ba19b94f
DD
161available. The argument list is terminated by the first @code{NULL}
162pointer encountered. Pointers to empty strings are ignored.
163
164@end deftypefn
165
166@c argv.c:65
167@deftypefn Extension char** dupargv (char **@var{vector})
168
169Duplicate an argument vector. Simply scans through @var{vector},
170duplicating each argument until the terminating @code{NULL} is found.
5d852400 171Returns a pointer to the argument vector if successful. Returns
ba19b94f
DD
172@code{NULL} if there is insufficient memory to complete building the
173argument vector.
174
175@end deftypefn
176
39423523 177@c strerror.c:566
ba19b94f 178@deftypefn Extension int errno_max (void)
39423523
DD
179
180Returns the maximum @code{errno} value for which a corresponding
181symbolic name or message is available. Note that in the case where we
182use the @code{sys_errlist} supplied by the system, it is possible for
183there to be more symbolic names than messages, or vice versa. In
184fact, the manual page for @code{perror(3C)} explicitly warns that one
185should check the size of the table (@code{sys_nerr}) before indexing
186it, since new error codes may be added to the system before they are
187added to the table. Thus @code{sys_nerr} might be smaller than value
99b58139 188implied by the largest @code{errno} value defined in @code{<errno.h>}.
39423523
DD
189
190We return the maximum value that can be used to obtain a meaningful
191symbolic name or message.
192
193@end deftypefn
194
ba19b94f
DD
195@c fdmatch.c:23
196@deftypefn Extension int fdmatch (int @var{fd1}, int @var{fd2})
197
198Check to see if two open file descriptors refer to the same file.
199This is useful, for example, when we have an open file descriptor for
200an unnamed file, and the name of a file that we believe to correspond
201to that fd. This can happen when we are exec'd with an already open
202file (@code{stdout} for example) or from the SVR4 @file{/proc} calls
203that return open file descriptors for mapped address spaces. All we
204have to do is open the file by name and check the two file descriptors
205for a match, which is done by comparing major and minor device numbers
206and inode numbers.
207
208@end deftypefn
209
210@c ffs.c:3
211@deftypefn Supplemental int ffs (int @var{valu})
212
5d852400 213Find the first (least significant) bit set in @var{valu}. Bits are
ba19b94f
DD
214numbered from right to left, starting with bit 1 (corresponding to the
215value 1). If @var{valu} is zero, zero is returned.
216
217@end deftypefn
218
219@c fnmatch.txh:1
220@deftypefn Replacement int fnmatch (const char *@var{pattern}, const char *@var{string}, int @var{flags})
221
222Matches @var{string} against @var{pattern}, returning zero if it
223matches, @code{FNM_NOMATCH} if not. @var{pattern} may contain the
224wildcards @code{?} to match any one character, @code{*} to match any
225zero or more characters, or a set of alternate characters in square
226brackets, like @samp{[a-gt8]}, which match one character (@code{a}
227through @code{g}, or @code{t}, or @code{8}, in this example) if that one
5d852400 228character is in the set. A set may be inverted (i.e., match anything
ba19b94f
DD
229except what's in the set) by giving @code{^} or @code{!} as the first
230character in the set. To include those characters in the set, list them
231as anything other than the first character of the set. To include a
232dash in the set, list it last in the set. A backslash character makes
233the following character not special, so for example you could match
234against a literal asterisk with @samp{\*}. To match a literal
235backslash, use @samp{\\}.
236
237@code{flags} controls various aspects of the matching process, and is a
238boolean OR of zero or more of the following values (defined in
5d852400 239@code{<fnmatch.h>}):
ba19b94f
DD
240
241@table @code
242
243@item FNM_PATHNAME
244@itemx FNM_FILE_NAME
245@var{string} is assumed to be a path name. No wildcard will ever match
246@code{/}.
247
248@item FNM_NOESCAPE
249Do not interpret backslashes as quoting the following special character.
250
251@item FNM_PERIOD
252A leading period (at the beginning of @var{string}, or if
253@code{FNM_PATHNAME} after a slash) is not matched by @code{*} or
254@code{?} but must be matched explicitly.
255
256@item FNM_LEADING_DIR
257Means that @var{string} also matches @var{pattern} if some initial part
258of @var{string} matches, and is followed by @code{/} and zero or more
259characters. For example, @samp{foo*} would match either @samp{foobar}
260or @samp{foobar/grill}.
261
262@item FNM_CASEFOLD
263Ignores case when performing the comparison.
264
265@end table
266
267@end deftypefn
268
269@c argv.c:111
270@deftypefn Extension void freeargv (char **@var{vector})
271
272Free an argument vector that was built using @code{buildargv}. Simply
273scans through @var{vector}, freeing the memory for each argument until
274the terminating @code{NULL} is found, and then frees @var{vector}
275itself.
276
277@end deftypefn
278
2a80c0a4 279@c getruntime.c:82
5d852400 280@deftypefn Replacement long get_run_time (void)
ba19b94f
DD
281
282Returns the time used so far, in microseconds. If possible, this is
283the time used by this process, else it is the elapsed time since the
284process started.
285
286@end deftypefn
287
39423523 288@c getcwd.c:6
99b58139 289@deftypefn Supplemental char* getcwd (char *@var{pathname}, int @var{len})
39423523
DD
290
291Copy the absolute pathname for the current working directory into
292@var{pathname}, which is assumed to point to a buffer of at least
293@var{len} bytes, and return a pointer to the buffer. If the current
294directory's path doesn't fit in @var{len} characters, the result is
99b58139 295@code{NULL} and @code{errno} is set. If @var{pathname} is a null pointer,
39423523
DD
296@code{getcwd} will obtain @var{len} bytes of space using
297@code{malloc}.
298
299@end deftypefn
300
301@c getpagesize.c:5
99b58139 302@deftypefn Supplemental int getpagesize (void)
39423523
DD
303
304Returns the number of bytes in a page of memory. This is the
305granularity of many of the system memory management routines. No
306guarantee is made as to whether or not it is the same as the basic
307memory management hardware page size.
308
309@end deftypefn
310
311@c getpwd.c:5
99b58139 312@deftypefn Supplemental char* getpwd (void)
39423523
DD
313
314Returns the current working directory. This implementation caches the
315result on the assumption that the process will not call @code{chdir}
316between calls to @code{getpwd}.
317
318@end deftypefn
319
7dd4d42a
DD
320@c hex.c:25
321@deftypefn Extension void hex_init (void)
322
323Initializes the array mapping the current character set to
324corresponding hex values. This function must be called before any
2a80c0a4
DD
325call to @code{hex_p} or @code{hex_value}. If you fail to call it, a
326default ASCII-based table will normally be used on ASCII systems.
7dd4d42a
DD
327
328@end deftypefn
329
2a80c0a4 330@c hex.c:34
7dd4d42a
DD
331@deftypefn Extension int hex_p (int @var{c})
332
333Evaluates to non-zero if the given character is a valid hex character,
334or zero if it is not. Note that the value you pass will be cast to
335@code{unsigned char} within the macro.
336
337@end deftypefn
338
2a80c0a4 339@c hex.c:42
7dd4d42a
DD
340@deftypefn Extension int hex_value (int @var{c})
341
342Returns the numeric equivalent of the given character when interpreted
343as a hexidecimal digit. The result is undefined if you pass an
344invalid hex digit. Note that the value you pass will be cast to
345@code{unsigned char} within the macro.
346
347@end deftypefn
348
39423523
DD
349@c index.c:5
350@deftypefn Supplemental char* index (char *@var{s}, int @var{c})
351
fa9f0e33 352Returns a pointer to the first occurrence of the character @var{c} in
99b58139 353the string @var{s}, or @code{NULL} if not found. The use of @code{index} is
39423523
DD
354deprecated in new programs in favor of @code{strchr}.
355
356@end deftypefn
357
ba19b94f
DD
358@c insque.c:6
359@deftypefn Supplemental void insque (struct qelem *@var{elem}, struct qelem *@var{pred})
360@deftypefnx Supplemental void remque (struct qelem *@var{elem})
361
362Routines to manipulate queues built from doubly linked lists. The
363@code{insque} routine inserts @var{elem} in the queue immediately
364after @var{pred}. The @code{remque} routine removes @var{elem} from
365its containing queue. These routines expect to be passed pointers to
366structures which have as their first members a forward pointer and a
367back pointer, like this prototype (although no prototype is provided):
368
369@example
370struct qelem @{
371 struct qelem *q_forw;
372 struct qelem *q_back;
373 char q_data[];
374@};
375@end example
376
377@end deftypefn
378
379@c lbasename.c:23
380@deftypefn Replacement {const char*} lbasename (const char *@var{name})
381
382Given a pointer to a string containing a typical pathname
383(@samp{/usr/src/cmd/ls/ls.c} for example), returns a pointer to the
384last component of the pathname (@samp{ls.c} in this case). The
385returned pointer is guaranteed to lie within the original
386string. This latter fact is not true of many vendor C
387libraries, which return special strings or modify the passed
388strings for particular input.
389
390In particular, the empty string returns the same empty string,
391and a path ending in @code{/} returns the empty string after it.
392
393@end deftypefn
394
ba61a412
DJ
395@c lrealpath.c:25
396@deftypefn Replacement {const char*} lrealpath (const char *@var{name})
397
398Given a pointer to a string containing a pathname, returns a canonical
399version of the filename. Symlinks will be resolved, and ``.'' and ``..''
400components will be simplified. The returned value will be allocated using
10b57b38 401@code{malloc}, or @code{NULL} will be returned on a memory allocation error.
2a80c0a4 402
ba61a412 403@end deftypefn
2a80c0a4 404
ba61a412
DJ
405@c make-relative-prefix.c:24
406@deftypefn Extension {const char*} make_relative_prefix (const char *@var{progname}, const char *@var{bin_prefix}, const char *@var{prefix})
2a80c0a4 407
ba61a412
DJ
408Given three paths @var{progname}, @var{bin_prefix}, @var{prefix},
409return the path that is in the same position relative to
410@var{progname}'s directory as @var{prefix} is relative to
411@var{bin_prefix}. That is, a string starting with the directory
412portion of @var{progname}, followed by a relative pathname of the
413difference between @var{bin_prefix} and @var{prefix}.
414
415If @var{progname} does not contain any directory separators,
416@code{make_relative_prefix} will search @env{PATH} to find a program
417named @var{progname}. Also, if @var{progname} is a symbolic link,
418the symbolic link will be resolved.
419
420For example, if @var{bin_prefix} is @code{/alpha/beta/gamma/gcc/delta},
421@var{prefix} is @code{/alpha/beta/gamma/omega/}, and @var{progname} is
422@code{/red/green/blue/gcc}, then this function will return
423@code{/red/green/blue/../../omega/}.
424
425The return value is normally allocated via @code{malloc}. If no
426relative prefix can be found, return @code{NULL}.
2a80c0a4
DD
427
428@end deftypefn
429
ba19b94f
DD
430@c make-temp-file.c:138
431@deftypefn Replacement char* make_temp_file (const char *@var{suffix})
432
433Return a temporary file name (as a string) or @code{NULL} if unable to
434create one. @var{suffix} is a suffix to append to the file name. The
5d852400 435string is @code{malloc}ed, and the temporary file has been created.
ba19b94f
DD
436
437@end deftypefn
438
39423523
DD
439@c memchr.c:3
440@deftypefn Supplemental void* memchr (const void *@var{s}, int @var{c}, size_t @var{n})
441
99b58139 442This function searches memory starting at @code{*@var{s}} for the
39423523
DD
443character @var{c}. The search only ends with the first occurrence of
444@var{c}, or after @var{length} characters; in particular, a null
445character does not terminate the search. If the character @var{c} is
99b58139
DD
446found within @var{length} characters of @code{*@var{s}}, a pointer
447to the character is returned. If @var{c} is not found, then @code{NULL} is
39423523
DD
448returned.
449
450@end deftypefn
451
452@c memcmp.c:6
453@deftypefn Supplemental int memcmp (const void *@var{x}, const void *@var{y}, size_t @var{count})
454
455Compares the first @var{count} bytes of two areas of memory. Returns
456zero if they are the same, a value less than zero if @var{x} is
457lexically less than @var{y}, or a value greater than zero if @var{x}
458is lexically greater than @var{y}. Note that lexical order is determined
459as if comparing unsigned char arrays.
460
461@end deftypefn
462
463@c memcpy.c:6
464@deftypefn Supplemental void* memcpy (void *@var{out}, const void *@var{in}, size_t @var{length})
465
466Copies @var{length} bytes from memory region @var{in} to region
467@var{out}. Returns a pointer to @var{out}.
468
469@end deftypefn
470
471@c memmove.c:6
472@deftypefn Supplemental void* memmove (void *@var{from}, const void *@var{to}, size_t @var{count})
473
474Copies @var{count} bytes from memory area @var{from} to memory area
475@var{to}, returning a pointer to @var{to}.
476
477@end deftypefn
478
10b57b38
DD
479@c mempcpy.c:23
480@deftypefn Supplemental void* mempcpy (void *@var{out}, const void *@var{in}, size_t @var{length})
481
482Copies @var{length} bytes from memory region @var{in} to region
483@var{out}. Returns a pointer to @var{out} + @var{length}.
484
485@end deftypefn
486
39423523
DD
487@c memset.c:6
488@deftypefn Supplemental void* memset (void *@var{s}, int @var{c}, size_t @var{count})
489
490Sets the first @var{count} bytes of @var{s} to the constant byte
491@var{c}, returning a pointer to @var{s}.
492
493@end deftypefn
494
ba19b94f
DD
495@c mkstemps.c:54
496@deftypefn Replacement int mkstemps (char *@var{template}, int @var{suffix_len})
497
498Generate a unique temporary file name from @var{template}.
499@var{template} has the form:
500
501@example
5d852400 502 @var{path}/ccXXXXXX@var{suffix}
ba19b94f
DD
503@end example
504
5d852400
DD
505@var{suffix_len} tells us how long @var{suffix} is (it can be zero
506length). The last six characters of @var{template} before @var{suffix}
507must be @samp{XXXXXX}; they are replaced with a string that makes the
ba19b94f
DD
508filename unique. Returns a file descriptor open on the file for
509reading and writing.
510
511@end deftypefn
512
5a17353c 513@c pexecute.txh:1
ba19b94f
DD
514@deftypefn Extension int pexecute (const char *@var{program}, char * const *@var{argv}, const char *@var{this_pname}, const char *@var{temp_base}, char **@var{errmsg_fmt}, char **@var{errmsg_arg}, int flags)
515
516Executes a program.
517
518@var{program} and @var{argv} are the arguments to
519@code{execv}/@code{execvp}.
520
5d852400 521@var{this_pname} is name of the calling program (i.e., @code{argv[0]}).
ba19b94f
DD
522
523@var{temp_base} is the path name, sans suffix, of a temporary file to
524use if needed. This is currently only needed for MS-DOS ports that
525don't use @code{go32} (do any still exist?). Ports that don't need it
526can pass @code{NULL}.
527
5a17353c
DD
528(@code{@var{flags} & PEXECUTE_SEARCH}) is non-zero if @env{PATH}
529should be searched (??? It's not clear that GCC passes this flag
530correctly). (@code{@var{flags} & PEXECUTE_FIRST}) is nonzero for the
531first process in chain. (@code{@var{flags} & PEXECUTE_FIRST}) is
532nonzero for the last process in chain. The first/last flags could be
533simplified to only mark the last of a chain of processes but that
534requires the caller to always mark the last one (and not give up
535early if some error occurs). It's more robust to require the caller
536to mark both ends of the chain.
ba19b94f
DD
537
538The result is the pid on systems like Unix where we
539@code{fork}/@code{exec} and on systems like WIN32 and OS/2 where we
540use @code{spawn}. It is up to the caller to wait for the child.
541
5d852400 542The result is the @code{WEXITSTATUS} on systems like MS-DOS where we
ba19b94f
DD
543@code{spawn} and wait for the child here.
544
545Upon failure, @var{errmsg_fmt} and @var{errmsg_arg} are set to the
546text of the error message with an optional argument (if not needed,
5d852400 547@var{errmsg_arg} is set to @code{NULL}), and @minus{}1 is returned.
ba19b94f
DD
548@code{errno} is available to the caller to use.
549
550@end deftypefn
551
552@c strsignal.c:547
553@deftypefn Supplemental void psignal (unsigned @var{signo}, char *@var{message})
554
555Print @var{message} to the standard error, followed by a colon,
556followed by the description of the signal specified by @var{signo},
557followed by a newline.
558
559@end deftypefn
560
39423523
DD
561@c putenv.c:21
562@deftypefn Supplemental int putenv (const char *@var{string})
563
564Uses @code{setenv} or @code{unsetenv} to put @var{string} into
565the environment or remove it. If @var{string} is of the form
99b58139 566@samp{name=value} the string is added; if no @samp{=} is present the
39423523
DD
567name is unset/removed.
568
569@end deftypefn
570
5a17353c 571@c pexecute.txh:39
ba19b94f
DD
572@deftypefn Extension int pwait (int @var{pid}, int *@var{status}, int @var{flags})
573
574Waits for a program started by @code{pexecute} to finish.
575
576@var{pid} is the process id of the task to wait for. @var{status} is
5a17353c
DD
577the `status' argument to wait. @var{flags} is currently unused
578(allows future enhancement without breaking upward compatibility).
579Pass 0 for now.
ba19b94f
DD
580
581The result is the pid of the child reaped, or -1 for failure
582(@code{errno} says why).
583
5a17353c
DD
584On systems that don't support waiting for a particular child,
585@var{pid} is ignored. On systems like MS-DOS that don't really
586multitask @code{pwait} is just a mechanism to provide a consistent
587interface for the caller.
ba19b94f
DD
588
589@end deftypefn
590
591@c random.c:39
5d852400 592@deftypefn Supplement {long int} random (void)
ba19b94f
DD
593@deftypefnx Supplement void srandom (unsigned int @var{seed})
594@deftypefnx Supplement void* initstate (unsigned int @var{seed}, void *@var{arg_state}, unsigned long @var{n})
595@deftypefnx Supplement void* setstate (void *@var{arg_state})
596
597Random number functions. @code{random} returns a random number in the
5d852400 598range 0 to @code{LONG_MAX}. @code{srandom} initializes the random
ba19b94f
DD
599number generator to some starting point determined by @var{seed}
600(else, the values returned by @code{random} are always the same for each
5d852400 601run of the program). @code{initstate} and @code{setstate} allow fine-grained
ba19b94f
DD
602control over the state of the random number generator.
603
604@end deftypefn
605
606@c concat.c:177
5d852400 607@deftypefn Extension char* reconcat (char *@var{optr}, const char *@var{s1}, @dots{}, @code{NULL})
ba19b94f
DD
608
609Same as @code{concat}, except that if @var{optr} is not @code{NULL} it
610is freed after the string is created. This is intended to be useful
611when you're extending an existing string or building up a string in a
612loop:
613
614@example
615 str = reconcat (str, "pre-", str, NULL);
616@end example
617
618@end deftypefn
619
39423523
DD
620@c rename.c:6
621@deftypefn Supplemental int rename (const char *@var{old}, const char *@var{new})
622
623Renames a file from @var{old} to @var{new}. If @var{new} already
624exists, it is removed.
625
626@end deftypefn
627
628@c rindex.c:5
629@deftypefn Supplemental char* rindex (const char *@var{s}, int @var{c})
630
fa9f0e33 631Returns a pointer to the last occurrence of the character @var{c} in
99b58139 632the string @var{s}, or @code{NULL} if not found. The use of @code{rindex} is
39423523
DD
633deprecated in new programs in favor of @code{strrchr}.
634
635@end deftypefn
636
637@c setenv.c:22
638@deftypefn Supplemental int setenv (const char *@var{name}, const char *@var{value}, int @var{overwrite})
639@deftypefnx Supplemental void unsetenv (const char *@var{name})
640
641@code{setenv} adds @var{name} to the environment with value
642@var{value}. If the name was already present in the environment,
56056af5 643the new value will be stored only if @var{overwrite} is nonzero.
39423523
DD
644The companion @code{unsetenv} function removes @var{name} from the
645environment. This implementation is not safe for multithreaded code.
646
647@end deftypefn
648
ba19b94f 649@c strsignal.c:353
5d852400 650@deftypefn Extension int signo_max (void)
ba19b94f
DD
651
652Returns the maximum signal value for which a corresponding symbolic
653name or message is available. Note that in the case where we use the
654@code{sys_siglist} supplied by the system, it is possible for there to
655be more symbolic names than messages, or vice versa. In fact, the
656manual page for @code{psignal(3b)} explicitly warns that one should
657check the size of the table (@code{NSIG}) before indexing it, since
658new signal codes may be added to the system before they are added to
659the table. Thus @code{NSIG} might be smaller than value implied by
660the largest signo value defined in @code{<signal.h>}.
661
662We return the maximum value that can be used to obtain a meaningful
663symbolic name or message.
664
665@end deftypefn
666
39423523
DD
667@c sigsetmask.c:8
668@deftypefn Supplemental int sigsetmask (int @var{set})
669
670Sets the signal mask to the one provided in @var{set} and returns
671the old mask (which, for libiberty's implementation, will always
672be the value @code{1}).
673
674@end deftypefn
675
2ed1e5cc
DD
676@c snprintf.c:28
677@deftypefn Supplemental int snprintf (char *@var{buf}, size_t @var{n}, const char *@var{format}, ...)
678
679This function is similar to sprintf, but it will print at most @var{n}
680characters. On error the return value is -1, otherwise it returns the
681number of characters that would have been printed had @var{n} been
682sufficiently large, regardless of the actual value of @var{n}. Note
683some pre-C99 system libraries do not implement this correctly so users
684cannot generally rely on the return value if the system version of
685this function is used.
686
687@end deftypefn
688
ba19b94f
DD
689@c spaces.c:22
690@deftypefn Extension char* spaces (int @var{count})
691
692Returns a pointer to a memory region filled with the specified
693number of spaces and null terminated. The returned pointer is
694valid until at least the next call.
695
696@end deftypefn
697
10b57b38
DD
698@c stpcpy.c:23
699@deftypefn Supplemental char* stpcpy (char *@var{dst}, const char *@var{src})
700
701Copies the string @var{src} into @var{dst}. Returns a pointer to
702@var{dst} + strlen(@var{src}).
703
704@end deftypefn
705
706@c stpncpy.c:23
707@deftypefn Supplemental char* stpncpy (char *@var{dst}, const char *@var{src}, size_t @var{len})
708
709Copies the string @var{src} into @var{dst}, copying exactly @var{len}
710and padding with zeros if necessary. If @var{len} < strlen(@var{src})
711then return @var{dst} + @var{len}, otherwise returns @var{dst} +
712strlen(@var{src}).
713
714@end deftypefn
715
39423523
DD
716@c strcasecmp.c:15
717@deftypefn Supplemental int strcasecmp (const char *@var{s1}, const char *@var{s2})
718
719A case-insensitive @code{strcmp}.
720
721@end deftypefn
722
723@c strchr.c:6
724@deftypefn Supplemental char* strchr (const char *@var{s}, int @var{c})
725
fa9f0e33 726Returns a pointer to the first occurrence of the character @var{c} in
99b58139 727the string @var{s}, or @code{NULL} if not found. If @var{c} is itself the
39423523
DD
728null character, the results are undefined.
729
730@end deftypefn
731
732@c strdup.c:3
733@deftypefn Supplemental char* strdup (const char *@var{s})
734
735Returns a pointer to a copy of @var{s} in memory obtained from
99b58139 736@code{malloc}, or @code{NULL} if insufficient memory was available.
39423523
DD
737
738@end deftypefn
739
740@c strerror.c:670
ba19b94f 741@deftypefn Replacement {const char*} strerrno (int @var{errnum})
39423523
DD
742
743Given an error number returned from a system call (typically returned
744in @code{errno}), returns a pointer to a string containing the
99b58139 745symbolic name of that error number, as found in @code{<errno.h>}.
39423523
DD
746
747If the supplied error number is within the valid range of indices for
748symbolic names, but no name is available for the particular error
ba19b94f 749number, then returns the string @samp{Error @var{num}}, where @var{num}
fa9f0e33 750is the error number.
39423523
DD
751
752If the supplied error number is not within the range of valid
99b58139 753indices, then returns @code{NULL}.
39423523
DD
754
755The contents of the location pointed to are only guaranteed to be
fa9f0e33 756valid until the next call to @code{strerrno}.
39423523
DD
757
758@end deftypefn
759
760@c strerror.c:602
ba19b94f 761@deftypefn Supplemental char* strerror (int @var{errnoval})
39423523
DD
762
763Maps an @code{errno} number to an error message string, the contents
764of which are implementation defined. On systems which have the
765external variables @code{sys_nerr} and @code{sys_errlist}, these
766strings will be the same as the ones used by @code{perror}.
767
768If the supplied error number is within the valid range of indices for
769the @code{sys_errlist}, but no message is available for the particular
ba19b94f 770error number, then returns the string @samp{Error @var{num}}, where
fa9f0e33 771@var{num} is the error number.
39423523
DD
772
773If the supplied error number is not a valid index into
99b58139 774@code{sys_errlist}, returns @code{NULL}.
39423523
DD
775
776The returned string is only guaranteed to be valid only until the
777next call to @code{strerror}.
778
779@end deftypefn
780
781@c strncasecmp.c:15
782@deftypefn Supplemental int strncasecmp (const char *@var{s1}, const char *@var{s2})
783
784A case-insensitive @code{strncmp}.
785
786@end deftypefn
787
788@c strncmp.c:6
789@deftypefn Supplemental int strncmp (const char *@var{s1}, const char *@var{s2}, size_t @var{n})
790
791Compares the first @var{n} bytes of two strings, returning a value as
792@code{strcmp}.
793
794@end deftypefn
795
796@c strrchr.c:6
797@deftypefn Supplemental char* strrchr (const char *@var{s}, int @var{c})
798
fa9f0e33 799Returns a pointer to the last occurrence of the character @var{c} in
99b58139 800the string @var{s}, or @code{NULL} if not found. If @var{c} is itself the
39423523
DD
801null character, the results are undefined.
802
803@end deftypefn
804
ba19b94f
DD
805@c strsignal.c:388
806@deftypefn Supplemental {const char *} strsignal (int @var{signo})
807
808Maps an signal number to an signal message string, the contents of
809which are implementation defined. On systems which have the external
810variable @code{sys_siglist}, these strings will be the same as the
811ones used by @code{psignal()}.
812
813If the supplied signal number is within the valid range of indices for
814the @code{sys_siglist}, but no message is available for the particular
815signal number, then returns the string @samp{Signal @var{num}}, where
816@var{num} is the signal number.
817
818If the supplied signal number is not a valid index into
819@code{sys_siglist}, returns @code{NULL}.
820
821The returned string is only guaranteed to be valid only until the next
822call to @code{strsignal}.
823
824@end deftypefn
825
826@c strsignal.c:452
827@deftypefn Extension {const char*} strsigno (int @var{signo})
828
829Given an signal number, returns a pointer to a string containing the
830symbolic name of that signal number, as found in @code{<signal.h>}.
831
832If the supplied signal number is within the valid range of indices for
833symbolic names, but no name is available for the particular signal
834number, then returns the string @samp{Signal @var{num}}, where
835@var{num} is the signal number.
836
837If the supplied signal number is not within the range of valid
838indices, then returns @code{NULL}.
839
840The contents of the location pointed to are only guaranteed to be
841valid until the next call to @code{strsigno}.
842
843@end deftypefn
844
39423523
DD
845@c strstr.c:6
846@deftypefn Supplemental char* strstr (const char *@var{string}, const char *@var{sub})
847
848This function searches for the substring @var{sub} in the string
fa9f0e33 849@var{string}, not including the terminating null characters. A pointer
99b58139 850to the first occurrence of @var{sub} is returned, or @code{NULL} if the
39423523
DD
851substring is absent. If @var{sub} points to a string with zero
852length, the function returns @var{string}.
853
854@end deftypefn
855
856@c strtod.c:27
857@deftypefn Supplemental double strtod (const char *@var{string}, char **@var{endptr})
858
56056af5 859This ISO C function converts the initial portion of @var{string} to a
99b58139 860@code{double}. If @var{endptr} is not @code{NULL}, a pointer to the
39423523
DD
861character after the last character used in the conversion is stored in
862the location referenced by @var{endptr}. If no conversion is
863performed, zero is returned and the value of @var{string} is stored in
864the location referenced by @var{endptr}.
865
866@end deftypefn
867
868@c strerror.c:730
ba19b94f 869@deftypefn Extension int strtoerrno (const char *@var{name})
39423523 870
99b58139 871Given the symbolic name of a error number (e.g., @code{EACCES}), map it
39423523
DD
872to an errno value. If no translation is found, returns 0.
873
874@end deftypefn
875
876@c strtol.c:33
877@deftypefn Supplemental {long int} strtol (const char *@var{string}, char **@var{endptr}, int @var{base})
ba19b94f 878@deftypefnx Supplemental {unsigned long int} strtoul (const char *@var{string}, char **@var{endptr}, int @var{base})
39423523
DD
879
880The @code{strtol} function converts the string in @var{string} to a
881long integer value according to the given @var{base}, which must be
882between 2 and 36 inclusive, or be the special value 0. If @var{base}
883is 0, @code{strtol} will look for the prefixes @code{0} and @code{0x}
884to indicate bases 8 and 16, respectively, else default to base 10.
885When the base is 16 (either explicitly or implicitly), a prefix of
fa9f0e33 886@code{0x} is allowed. The handling of @var{endptr} is as that of
ba19b94f
DD
887@code{strtod} above. The @code{strtoul} function is the same, except
888that the converted value is unsigned.
889
890@end deftypefn
891
892@c strsignal.c:507
893@deftypefn Extension int strtosigno (const char *@var{name})
894
895Given the symbolic name of a signal, map it to a signal number. If no
896translation is found, returns 0.
39423523
DD
897
898@end deftypefn
899
900@c tmpnam.c:3
901@deftypefn Supplemental char* tmpnam (char *@var{s})
902
903This function attempts to create a name for a temporary file, which
904will be a valid file name yet not exist when @code{tmpnam} checks for
905it. @var{s} must point to a buffer of at least @code{L_tmpnam} bytes,
99b58139 906or be @code{NULL}. Use of this function creates a security risk, and it must
39423523
DD
907not be used in new projects. Use @code{mkstemp} instead.
908
909@end deftypefn
910
ba19b94f 911@c vasprintf.c:48
5d852400 912@deftypefn Extension int vasprintf (char **@var{resptr}, const char *@var{format}, va_list @var{args})
ba19b94f
DD
913
914Like @code{vsprintf}, but instead of passing a pointer to a buffer,
915you pass a pointer to a pointer. This function will compute the size
916of the buffer needed, allocate memory with @code{malloc}, and store a
917pointer to the allocated memory in @code{*@var{resptr}}. The value
918returned is the same as @code{vsprintf} would return. If memory could
919not be allocated, zero is returned and @code{NULL} is stored in
920@code{*@var{resptr}}.
921
922@end deftypefn
923
39423523 924@c vfork.c:6
99b58139 925@deftypefn Supplemental int vfork (void)
39423523
DD
926
927Emulates @code{vfork} by calling @code{fork} and returning its value.
928
929@end deftypefn
930
931@c vprintf.c:3
932@deftypefn Supplemental int vprintf (const char *@var{format}, va_list @var{ap})
933@deftypefnx Supplemental int vfprintf (FILE *@var{stream}, const char *@var{format}, va_list @var{ap})
934@deftypefnx Supplemental int vsprintf (char *@var{str}, const char *@var{format}, va_list @var{ap})
935
936These functions are the same as @code{printf}, @code{fprintf}, and
937@code{sprintf}, respectively, except that they are called with a
938@code{va_list} instead of a variable number of arguments. Note that
939they do not call @code{va_end}; this is the application's
940responsibility. In @libib{} they are implemented in terms of the
941nonstandard but common function @code{_doprnt}.
942
943@end deftypefn
944
2ed1e5cc
DD
945@c vsnprintf.c:28
946@deftypefn Supplemental int vsnprintf (char *@var{buf}, size_t @var{n}, const char *@var{format}, va_list @var{ap})
947
948This function is similar to vsprintf, but it will print at most
949@var{n} characters. On error the return value is -1, otherwise it
950returns the number of characters that would have been printed had
951@var{n} been sufficiently large, regardless of the actual value of
952@var{n}. Note some pre-C99 system libraries do not implement this
953correctly so users cannot generally rely on the return value if the
954system version of this function is used.
955
956@end deftypefn
957
39423523
DD
958@c waitpid.c:3
959@deftypefn Supplemental int waitpid (int @var{pid}, int *@var{status}, int)
960
961This is a wrapper around the @code{wait} function. Any ``special''
962values of @var{pid} depend on your implementation of @code{wait}, as
963does the return value. The third argument is unused in @libib{}.
964
965@end deftypefn
966
967@c xatexit.c:11
968@deftypefun int xatexit (void (*@var{fn}) (void))
969
970Behaves as the standard @code{atexit} function, but with no limit on
99b58139 971the number of registered functions. Returns 0 on success, or @minus{}1 on
39423523
DD
972failure. If you use @code{xatexit} to register functions, you must use
973@code{xexit} to terminate your program.
974
975@end deftypefun
976
fa9f0e33 977@c xmalloc.c:38
99b58139 978@deftypefn Replacement void* xcalloc (size_t @var{nelem}, size_t @var{elsize})
39423523
DD
979
980Allocate memory without fail, and set it to zero. This routine functions
981like @code{calloc}, but will behave the same as @code{xmalloc} if memory
982cannot be found.
983
984@end deftypefn
985
986@c xexit.c:22
987@deftypefn Replacement void xexit (int @var{code})
988
989Terminates the program. If any functions have been registered with
fa9f0e33 990the @code{xatexit} replacement function, they will be called first.
39423523
DD
991Termination is handled via the system's normal @code{exit} call.
992
993@end deftypefn
994
995@c xmalloc.c:22
996@deftypefn Replacement void* xmalloc (size_t)
997
998Allocate memory without fail. If @code{malloc} fails, this will print
fa9f0e33
DD
999a message to @code{stderr} (using the name set by
1000@code{xmalloc_set_program_name},
39423523
DD
1001if any) and then call @code{xexit}. Note that it is therefore safe for
1002a program to contain @code{#define malloc xmalloc} in its source.
1003
1004@end deftypefn
1005
fa9f0e33 1006@c xmalloc.c:53
39423523
DD
1007@deftypefn Replacement void xmalloc_failed (size_t)
1008
1009This function is not meant to be called by client code, and is listed
1010here for completeness only. If any of the allocation routines fail, this
1011function will be called to print an error message and terminate execution.
1012
1013@end deftypefn
1014
fa9f0e33 1015@c xmalloc.c:46
39423523
DD
1016@deftypefn Replacement void xmalloc_set_program_name (const char *@var{name})
1017
1018You can use this to set the name of the program used by
1019@code{xmalloc_failed} when printing a failure message.
1020
1021@end deftypefn
1022
1023@c xmemdup.c:7
1024@deftypefn Replacement void* xmemdup (void *@var{input}, size_t @var{copy_size}, size_t @var{alloc_size})
1025
1026Duplicates a region of memory without fail. First, @var{alloc_size} bytes
1027are allocated, then @var{copy_size} bytes from @var{input} are copied into
1028it, and the new memory is returned. If fewer bytes are copied than were
1029allocated, the remaining memory is zeroed.
1030
1031@end deftypefn
1032
fa9f0e33 1033@c xmalloc.c:32
99b58139 1034@deftypefn Replacement void* xrealloc (void *@var{ptr}, size_t @var{size})
39423523
DD
1035Reallocate memory without fail. This routine functions like @code{realloc},
1036but will behave the same as @code{xmalloc} if memory cannot be found.
1037
1038@end deftypefn
1039
1040@c xstrdup.c:7
1041@deftypefn Replacement char* xstrdup (const char *@var{s})
1042
1043Duplicates a character string without fail, using @code{xmalloc} to
1044obtain memory.
1045
1046@end deftypefn
1047
1048@c xstrerror.c:7
1049@deftypefn Replacement char* xstrerror (int @var{errnum})
1050
1051Behaves exactly like the standard @code{strerror} function, but
99b58139 1052will never return a @code{NULL} pointer.
39423523
DD
1053
1054@end deftypefn
1055
1056
This page took 0.355983 seconds and 4 git commands to generate.