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