xref: /dflybsd-src/contrib/gdb-7/include/libiberty.h (revision 207ba6700e31c36bb4e38d4da221a4f86e466ee9)
15796c8dcSSimon Schubert /* Function declarations for libiberty.
25796c8dcSSimon Schubert 
35796c8dcSSimon Schubert    Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4a45ae5f8SJohn Marino    2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
55796c8dcSSimon Schubert 
65796c8dcSSimon Schubert    Note - certain prototypes declared in this header file are for
75796c8dcSSimon Schubert    functions whoes implementation copyright does not belong to the
85796c8dcSSimon Schubert    FSF.  Those prototypes are present in this file for reference
95796c8dcSSimon Schubert    purposes only and their presence in this file should not construed
105796c8dcSSimon Schubert    as an indication of ownership by the FSF of the implementation of
115796c8dcSSimon Schubert    those functions in any way or form whatsoever.
125796c8dcSSimon Schubert 
135796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
145796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
155796c8dcSSimon Schubert    the Free Software Foundation; either version 2, or (at your option)
165796c8dcSSimon Schubert    any later version.
175796c8dcSSimon Schubert 
185796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
195796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
205796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
215796c8dcSSimon Schubert    GNU General Public License for more details.
225796c8dcSSimon Schubert 
235796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
245796c8dcSSimon Schubert    along with this program; if not, write to the Free Software
255796c8dcSSimon Schubert    Foundation, Inc., 51 Franklin Street - Fifth Floor,
265796c8dcSSimon Schubert    Boston, MA 02110-1301, USA.
275796c8dcSSimon Schubert 
285796c8dcSSimon Schubert    Written by Cygnus Support, 1994.
295796c8dcSSimon Schubert 
305796c8dcSSimon Schubert    The libiberty library provides a number of functions which are
315796c8dcSSimon Schubert    missing on some operating systems.  We do not declare those here,
325796c8dcSSimon Schubert    to avoid conflicts with the system header files on operating
335796c8dcSSimon Schubert    systems that do support those functions.  In this file we only
345796c8dcSSimon Schubert    declare those functions which are specific to libiberty.  */
355796c8dcSSimon Schubert 
365796c8dcSSimon Schubert #ifndef LIBIBERTY_H
375796c8dcSSimon Schubert #define LIBIBERTY_H
385796c8dcSSimon Schubert 
395796c8dcSSimon Schubert #ifdef __cplusplus
405796c8dcSSimon Schubert extern "C" {
415796c8dcSSimon Schubert #endif
425796c8dcSSimon Schubert 
435796c8dcSSimon Schubert #include "ansidecl.h"
445796c8dcSSimon Schubert 
455796c8dcSSimon Schubert /* Get a definition for size_t.  */
465796c8dcSSimon Schubert #include <stddef.h>
475796c8dcSSimon Schubert /* Get a definition for va_list.  */
485796c8dcSSimon Schubert #include <stdarg.h>
495796c8dcSSimon Schubert 
505796c8dcSSimon Schubert #include <stdio.h>
515796c8dcSSimon Schubert 
525796c8dcSSimon Schubert /* If the OS supports it, ensure that the supplied stream is setup to
535796c8dcSSimon Schubert    avoid any multi-threaded locking.  Otherwise leave the FILE pointer
545796c8dcSSimon Schubert    unchanged.  If the stream is NULL do nothing.  */
555796c8dcSSimon Schubert 
565796c8dcSSimon Schubert extern void unlock_stream (FILE *);
575796c8dcSSimon Schubert 
585796c8dcSSimon Schubert /* If the OS supports it, ensure that the standard I/O streams, stdin,
595796c8dcSSimon Schubert    stdout and stderr are setup to avoid any multi-threaded locking.
605796c8dcSSimon Schubert    Otherwise do nothing.  */
615796c8dcSSimon Schubert 
625796c8dcSSimon Schubert extern void unlock_std_streams (void);
635796c8dcSSimon Schubert 
645796c8dcSSimon Schubert /* Open and return a FILE pointer.  If the OS supports it, ensure that
655796c8dcSSimon Schubert    the stream is setup to avoid any multi-threaded locking.  Otherwise
665796c8dcSSimon Schubert    return the FILE pointer unchanged.  */
675796c8dcSSimon Schubert 
685796c8dcSSimon Schubert extern FILE *fopen_unlocked (const char *, const char *);
695796c8dcSSimon Schubert extern FILE *fdopen_unlocked (int, const char *);
705796c8dcSSimon Schubert extern FILE *freopen_unlocked (const char *, const char *, FILE *);
715796c8dcSSimon Schubert 
725796c8dcSSimon Schubert /* Build an argument vector from a string.  Allocates memory using
735796c8dcSSimon Schubert    malloc.  Use freeargv to free the vector.  */
745796c8dcSSimon Schubert 
755796c8dcSSimon Schubert extern char **buildargv (const char *) ATTRIBUTE_MALLOC;
765796c8dcSSimon Schubert 
775796c8dcSSimon Schubert /* Free a vector returned by buildargv.  */
785796c8dcSSimon Schubert 
795796c8dcSSimon Schubert extern void freeargv (char **);
805796c8dcSSimon Schubert 
815796c8dcSSimon Schubert /* Duplicate an argument vector. Allocates memory using malloc.  Use
825796c8dcSSimon Schubert    freeargv to free the vector.  */
835796c8dcSSimon Schubert 
845796c8dcSSimon Schubert extern char **dupargv (char **) ATTRIBUTE_MALLOC;
855796c8dcSSimon Schubert 
865796c8dcSSimon Schubert /* Expand "@file" arguments in argv.  */
875796c8dcSSimon Schubert 
885796c8dcSSimon Schubert extern void expandargv PARAMS ((int *, char ***));
895796c8dcSSimon Schubert 
905796c8dcSSimon Schubert /* Write argv to an @-file, inserting necessary quoting.  */
915796c8dcSSimon Schubert 
925796c8dcSSimon Schubert extern int writeargv PARAMS ((char **, FILE *));
935796c8dcSSimon Schubert 
94a45ae5f8SJohn Marino /* Return the number of elements in argv.  */
95a45ae5f8SJohn Marino 
96a45ae5f8SJohn Marino extern int countargv (char**);
97a45ae5f8SJohn Marino 
985796c8dcSSimon Schubert /* Return the last component of a path name.  Note that we can't use a
995796c8dcSSimon Schubert    prototype here because the parameter is declared inconsistently
1005796c8dcSSimon Schubert    across different systems, sometimes as "char *" and sometimes as
1015796c8dcSSimon Schubert    "const char *" */
1025796c8dcSSimon Schubert 
1035796c8dcSSimon Schubert /* HAVE_DECL_* is a three-state macro: undefined, 0 or 1.  If it is
1045796c8dcSSimon Schubert    undefined, we haven't run the autoconf check so provide the
1055796c8dcSSimon Schubert    declaration without arguments.  If it is 0, we checked and failed
1065796c8dcSSimon Schubert    to find the declaration so provide a fully prototyped one.  If it
1075796c8dcSSimon Schubert    is 1, we found it so don't provide any declaration at all.  */
1085796c8dcSSimon Schubert #if !HAVE_DECL_BASENAME
10969e0f06dSSimon Schubert #if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || defined (__MINGW32__) || defined (HAVE_DECL_BASENAME)
110*207ba670SMatthew Dillon extern char *basename (char *);
1115796c8dcSSimon Schubert #else
1125796c8dcSSimon Schubert /* Do not allow basename to be used if there is no prototype seen.  We
1135796c8dcSSimon Schubert    either need to use the above prototype or have one from
1145796c8dcSSimon Schubert    autoconf which would result in HAVE_DECL_BASENAME being set.  */
1155796c8dcSSimon Schubert #define basename basename_cannot_be_used_without_a_prototype
1165796c8dcSSimon Schubert #endif
1175796c8dcSSimon Schubert #endif
1185796c8dcSSimon Schubert 
1195796c8dcSSimon Schubert /* A well-defined basename () that is always compiled in.  */
1205796c8dcSSimon Schubert 
1215796c8dcSSimon Schubert extern const char *lbasename (const char *);
1225796c8dcSSimon Schubert 
123cf7f2e2dSJohn Marino /* Same, but assumes DOS semantics (drive name, backslash is also a
124cf7f2e2dSJohn Marino    dir separator) regardless of host.  */
125cf7f2e2dSJohn Marino 
126cf7f2e2dSJohn Marino extern const char *dos_lbasename (const char *);
127cf7f2e2dSJohn Marino 
128cf7f2e2dSJohn Marino /* Same, but assumes Unix semantics (absolute paths always start with
129cf7f2e2dSJohn Marino    a slash, only forward slash is accepted as dir separator)
130cf7f2e2dSJohn Marino    regardless of host.  */
131cf7f2e2dSJohn Marino 
132cf7f2e2dSJohn Marino extern const char *unix_lbasename (const char *);
133cf7f2e2dSJohn Marino 
1345796c8dcSSimon Schubert /* A well-defined realpath () that is always compiled in.  */
1355796c8dcSSimon Schubert 
1365796c8dcSSimon Schubert extern char *lrealpath (const char *);
1375796c8dcSSimon Schubert 
1385796c8dcSSimon Schubert /* Concatenate an arbitrary number of strings.  You must pass NULL as
1395796c8dcSSimon Schubert    the last argument of this function, to terminate the list of
1405796c8dcSSimon Schubert    strings.  Allocates memory using xmalloc.  */
1415796c8dcSSimon Schubert 
1425796c8dcSSimon Schubert extern char *concat (const char *, ...) ATTRIBUTE_MALLOC ATTRIBUTE_SENTINEL;
1435796c8dcSSimon Schubert 
1445796c8dcSSimon Schubert /* Concatenate an arbitrary number of strings.  You must pass NULL as
1455796c8dcSSimon Schubert    the last argument of this function, to terminate the list of
1465796c8dcSSimon Schubert    strings.  Allocates memory using xmalloc.  The first argument is
1475796c8dcSSimon Schubert    not one of the strings to be concatenated, but if not NULL is a
1485796c8dcSSimon Schubert    pointer to be freed after the new string is created, similar to the
1495796c8dcSSimon Schubert    way xrealloc works.  */
1505796c8dcSSimon Schubert 
1515796c8dcSSimon Schubert extern char *reconcat (char *, const char *, ...) ATTRIBUTE_MALLOC ATTRIBUTE_SENTINEL;
1525796c8dcSSimon Schubert 
1535796c8dcSSimon Schubert /* Determine the length of concatenating an arbitrary number of
1545796c8dcSSimon Schubert    strings.  You must pass NULL as the last argument of this function,
1555796c8dcSSimon Schubert    to terminate the list of strings.  */
1565796c8dcSSimon Schubert 
1575796c8dcSSimon Schubert extern unsigned long concat_length (const char *, ...) ATTRIBUTE_SENTINEL;
1585796c8dcSSimon Schubert 
1595796c8dcSSimon Schubert /* Concatenate an arbitrary number of strings into a SUPPLIED area of
1605796c8dcSSimon Schubert    memory.  You must pass NULL as the last argument of this function,
1615796c8dcSSimon Schubert    to terminate the list of strings.  The supplied memory is assumed
1625796c8dcSSimon Schubert    to be large enough.  */
1635796c8dcSSimon Schubert 
1645796c8dcSSimon Schubert extern char *concat_copy (char *, const char *, ...) ATTRIBUTE_SENTINEL;
1655796c8dcSSimon Schubert 
1665796c8dcSSimon Schubert /* Concatenate an arbitrary number of strings into a GLOBAL area of
1675796c8dcSSimon Schubert    memory.  You must pass NULL as the last argument of this function,
1685796c8dcSSimon Schubert    to terminate the list of strings.  The supplied memory is assumed
1695796c8dcSSimon Schubert    to be large enough.  */
1705796c8dcSSimon Schubert 
1715796c8dcSSimon Schubert extern char *concat_copy2 (const char *, ...) ATTRIBUTE_SENTINEL;
1725796c8dcSSimon Schubert 
1735796c8dcSSimon Schubert /* This is the global area used by concat_copy2.  */
1745796c8dcSSimon Schubert 
1755796c8dcSSimon Schubert extern char *libiberty_concat_ptr;
1765796c8dcSSimon Schubert 
1775796c8dcSSimon Schubert /* Concatenate an arbitrary number of strings.  You must pass NULL as
1785796c8dcSSimon Schubert    the last argument of this function, to terminate the list of
1795796c8dcSSimon Schubert    strings.  Allocates memory using alloca.  The arguments are
1805796c8dcSSimon Schubert    evaluated twice!  */
1815796c8dcSSimon Schubert #define ACONCAT(ACONCAT_PARAMS) \
1825796c8dcSSimon Schubert   (libiberty_concat_ptr = (char *) alloca (concat_length ACONCAT_PARAMS + 1), \
1835796c8dcSSimon Schubert    concat_copy2 ACONCAT_PARAMS)
1845796c8dcSSimon Schubert 
1855796c8dcSSimon Schubert /* Check whether two file descriptors refer to the same file.  */
1865796c8dcSSimon Schubert 
1875796c8dcSSimon Schubert extern int fdmatch (int fd1, int fd2);
1885796c8dcSSimon Schubert 
1895796c8dcSSimon Schubert /* Return the position of the first bit set in the argument.  */
1905796c8dcSSimon Schubert /* Prototypes vary from system to system, so we only provide a
1915796c8dcSSimon Schubert    prototype on systems where we know that we need it.  */
1925796c8dcSSimon Schubert #if defined (HAVE_DECL_FFS) && !HAVE_DECL_FFS
1935796c8dcSSimon Schubert extern int ffs(int);
1945796c8dcSSimon Schubert #endif
1955796c8dcSSimon Schubert 
1965796c8dcSSimon Schubert /* Get the working directory.  The result is cached, so don't call
1975796c8dcSSimon Schubert    chdir() between calls to getpwd().  */
1985796c8dcSSimon Schubert 
1995796c8dcSSimon Schubert extern char * getpwd (void);
2005796c8dcSSimon Schubert 
2015796c8dcSSimon Schubert /* Get the current time.  */
2025796c8dcSSimon Schubert /* Prototypes vary from system to system, so we only provide a
2035796c8dcSSimon Schubert    prototype on systems where we know that we need it.  */
2045796c8dcSSimon Schubert #ifdef __MINGW32__
2055796c8dcSSimon Schubert /* Forward declaration to avoid #include <sys/time.h>.   */
2065796c8dcSSimon Schubert struct timeval;
2075796c8dcSSimon Schubert extern int gettimeofday (struct timeval *, void *);
2085796c8dcSSimon Schubert #endif
2095796c8dcSSimon Schubert 
2105796c8dcSSimon Schubert /* Get the amount of time the process has run, in microseconds.  */
2115796c8dcSSimon Schubert 
2125796c8dcSSimon Schubert extern long get_run_time (void);
2135796c8dcSSimon Schubert 
2145796c8dcSSimon Schubert /* Generate a relocated path to some installation directory.  Allocates
2155796c8dcSSimon Schubert    return value using malloc.  */
2165796c8dcSSimon Schubert 
2175796c8dcSSimon Schubert extern char *make_relative_prefix (const char *, const char *,
2185796c8dcSSimon Schubert                                    const char *) ATTRIBUTE_MALLOC;
2195796c8dcSSimon Schubert 
2205796c8dcSSimon Schubert /* Generate a relocated path to some installation directory without
2215796c8dcSSimon Schubert    attempting to follow any soft links.  Allocates
2225796c8dcSSimon Schubert    return value using malloc.  */
2235796c8dcSSimon Schubert 
2245796c8dcSSimon Schubert extern char *make_relative_prefix_ignore_links (const char *, const char *,
2255796c8dcSSimon Schubert 						const char *) ATTRIBUTE_MALLOC;
2265796c8dcSSimon Schubert 
2275796c8dcSSimon Schubert /* Choose a temporary directory to use for scratch files.  */
2285796c8dcSSimon Schubert 
2295796c8dcSSimon Schubert extern char *choose_temp_base (void) ATTRIBUTE_MALLOC;
2305796c8dcSSimon Schubert 
2315796c8dcSSimon Schubert /* Return a temporary file name or NULL if unable to create one.  */
2325796c8dcSSimon Schubert 
2335796c8dcSSimon Schubert extern char *make_temp_file (const char *) ATTRIBUTE_MALLOC;
2345796c8dcSSimon Schubert 
2355796c8dcSSimon Schubert /* Remove a link to a file unless it is special. */
2365796c8dcSSimon Schubert 
2375796c8dcSSimon Schubert extern int unlink_if_ordinary (const char *);
2385796c8dcSSimon Schubert 
2395796c8dcSSimon Schubert /* Allocate memory filled with spaces.  Allocates using malloc.  */
2405796c8dcSSimon Schubert 
2415796c8dcSSimon Schubert extern const char *spaces (int count);
2425796c8dcSSimon Schubert 
2435796c8dcSSimon Schubert /* Return the maximum error number for which strerror will return a
2445796c8dcSSimon Schubert    string.  */
2455796c8dcSSimon Schubert 
2465796c8dcSSimon Schubert extern int errno_max (void);
2475796c8dcSSimon Schubert 
2485796c8dcSSimon Schubert /* Return the name of an errno value (e.g., strerrno (EINVAL) returns
2495796c8dcSSimon Schubert    "EINVAL").  */
2505796c8dcSSimon Schubert 
2515796c8dcSSimon Schubert extern const char *strerrno (int);
2525796c8dcSSimon Schubert 
2535796c8dcSSimon Schubert /* Given the name of an errno value, return the value.  */
2545796c8dcSSimon Schubert 
2555796c8dcSSimon Schubert extern int strtoerrno (const char *);
2565796c8dcSSimon Schubert 
2575796c8dcSSimon Schubert /* ANSI's strerror(), but more robust.  */
2585796c8dcSSimon Schubert 
2595796c8dcSSimon Schubert extern char *xstrerror (int);
2605796c8dcSSimon Schubert 
2615796c8dcSSimon Schubert /* Return the maximum signal number for which strsignal will return a
2625796c8dcSSimon Schubert    string.  */
2635796c8dcSSimon Schubert 
2645796c8dcSSimon Schubert extern int signo_max (void);
2655796c8dcSSimon Schubert 
2665796c8dcSSimon Schubert /* Return a signal message string for a signal number
2675796c8dcSSimon Schubert    (e.g., strsignal (SIGHUP) returns something like "Hangup").  */
2685796c8dcSSimon Schubert /* This is commented out as it can conflict with one in system headers.
2695796c8dcSSimon Schubert    We still document its existence though.  */
2705796c8dcSSimon Schubert 
2715796c8dcSSimon Schubert /*extern const char *strsignal (int);*/
2725796c8dcSSimon Schubert 
2735796c8dcSSimon Schubert /* Return the name of a signal number (e.g., strsigno (SIGHUP) returns
2745796c8dcSSimon Schubert    "SIGHUP").  */
2755796c8dcSSimon Schubert 
2765796c8dcSSimon Schubert extern const char *strsigno (int);
2775796c8dcSSimon Schubert 
2785796c8dcSSimon Schubert /* Given the name of a signal, return its number.  */
2795796c8dcSSimon Schubert 
2805796c8dcSSimon Schubert extern int strtosigno (const char *);
2815796c8dcSSimon Schubert 
2825796c8dcSSimon Schubert /* Register a function to be run by xexit.  Returns 0 on success.  */
2835796c8dcSSimon Schubert 
2845796c8dcSSimon Schubert extern int xatexit (void (*fn) (void));
2855796c8dcSSimon Schubert 
2865796c8dcSSimon Schubert /* Exit, calling all the functions registered with xatexit.  */
2875796c8dcSSimon Schubert 
2885796c8dcSSimon Schubert extern void xexit (int status) ATTRIBUTE_NORETURN;
2895796c8dcSSimon Schubert 
2905796c8dcSSimon Schubert /* Set the program name used by xmalloc.  */
2915796c8dcSSimon Schubert 
2925796c8dcSSimon Schubert extern void xmalloc_set_program_name (const char *);
2935796c8dcSSimon Schubert 
2945796c8dcSSimon Schubert /* Report an allocation failure.  */
2955796c8dcSSimon Schubert extern void xmalloc_failed (size_t) ATTRIBUTE_NORETURN;
2965796c8dcSSimon Schubert 
2975796c8dcSSimon Schubert /* Allocate memory without fail.  If malloc fails, this will print a
2985796c8dcSSimon Schubert    message to stderr (using the name set by xmalloc_set_program_name,
2995796c8dcSSimon Schubert    if any) and then call xexit.  */
3005796c8dcSSimon Schubert 
3015796c8dcSSimon Schubert extern void *xmalloc (size_t) ATTRIBUTE_MALLOC;
3025796c8dcSSimon Schubert 
3035796c8dcSSimon Schubert /* Reallocate memory without fail.  This works like xmalloc.  Note,
3045796c8dcSSimon Schubert    realloc type functions are not suitable for attribute malloc since
3055796c8dcSSimon Schubert    they may return the same address across multiple calls. */
3065796c8dcSSimon Schubert 
3075796c8dcSSimon Schubert extern void *xrealloc (void *, size_t);
3085796c8dcSSimon Schubert 
3095796c8dcSSimon Schubert /* Allocate memory without fail and set it to zero.  This works like
3105796c8dcSSimon Schubert    xmalloc.  */
3115796c8dcSSimon Schubert 
3125796c8dcSSimon Schubert extern void *xcalloc (size_t, size_t) ATTRIBUTE_MALLOC;
3135796c8dcSSimon Schubert 
3145796c8dcSSimon Schubert /* Copy a string into a memory buffer without fail.  */
3155796c8dcSSimon Schubert 
3165796c8dcSSimon Schubert extern char *xstrdup (const char *) ATTRIBUTE_MALLOC;
3175796c8dcSSimon Schubert 
3185796c8dcSSimon Schubert /* Copy at most N characters from string into a buffer without fail.  */
3195796c8dcSSimon Schubert 
3205796c8dcSSimon Schubert extern char *xstrndup (const char *, size_t) ATTRIBUTE_MALLOC;
3215796c8dcSSimon Schubert 
3225796c8dcSSimon Schubert /* Copy an existing memory buffer to a new memory buffer without fail.  */
3235796c8dcSSimon Schubert 
3245796c8dcSSimon Schubert extern void *xmemdup (const void *, size_t, size_t) ATTRIBUTE_MALLOC;
3255796c8dcSSimon Schubert 
3265796c8dcSSimon Schubert /* Physical memory routines.  Return values are in BYTES.  */
3275796c8dcSSimon Schubert extern double physmem_total (void);
3285796c8dcSSimon Schubert extern double physmem_available (void);
3295796c8dcSSimon Schubert 
3305796c8dcSSimon Schubert /* Compute the 32-bit CRC of a block of memory.  */
3315796c8dcSSimon Schubert extern unsigned int xcrc32 (const unsigned char *, int, unsigned int);
3325796c8dcSSimon Schubert 
3335796c8dcSSimon Schubert /* These macros provide a K&R/C89/C++-friendly way of allocating structures
3345796c8dcSSimon Schubert    with nice encapsulation.  The XDELETE*() macros are technically
3355796c8dcSSimon Schubert    superfluous, but provided here for symmetry.  Using them consistently
3365796c8dcSSimon Schubert    makes it easier to update client code to use different allocators such
3375796c8dcSSimon Schubert    as new/delete and new[]/delete[].  */
3385796c8dcSSimon Schubert 
3395796c8dcSSimon Schubert /* Scalar allocators.  */
3405796c8dcSSimon Schubert 
3415796c8dcSSimon Schubert #define XALLOCA(T)		((T *) alloca (sizeof (T)))
3425796c8dcSSimon Schubert #define XNEW(T)			((T *) xmalloc (sizeof (T)))
3435796c8dcSSimon Schubert #define XCNEW(T)		((T *) xcalloc (1, sizeof (T)))
3445796c8dcSSimon Schubert #define XDUP(T, P)		((T *) xmemdup ((P), sizeof (T), sizeof (T)))
3455796c8dcSSimon Schubert #define XDELETE(P)		free ((void*) (P))
3465796c8dcSSimon Schubert 
3475796c8dcSSimon Schubert /* Array allocators.  */
3485796c8dcSSimon Schubert 
3495796c8dcSSimon Schubert #define XALLOCAVEC(T, N)	((T *) alloca (sizeof (T) * (N)))
3505796c8dcSSimon Schubert #define XNEWVEC(T, N)		((T *) xmalloc (sizeof (T) * (N)))
3515796c8dcSSimon Schubert #define XCNEWVEC(T, N)		((T *) xcalloc ((N), sizeof (T)))
3525796c8dcSSimon Schubert #define XDUPVEC(T, P, N)	((T *) xmemdup ((P), sizeof (T) * (N), sizeof (T) * (N)))
3535796c8dcSSimon Schubert #define XRESIZEVEC(T, P, N)	((T *) xrealloc ((void *) (P), sizeof (T) * (N)))
3545796c8dcSSimon Schubert #define XDELETEVEC(P)		free ((void*) (P))
3555796c8dcSSimon Schubert 
3565796c8dcSSimon Schubert /* Allocators for variable-sized structures and raw buffers.  */
3575796c8dcSSimon Schubert 
3585796c8dcSSimon Schubert #define XALLOCAVAR(T, S)	((T *) alloca ((S)))
3595796c8dcSSimon Schubert #define XNEWVAR(T, S)		((T *) xmalloc ((S)))
3605796c8dcSSimon Schubert #define XCNEWVAR(T, S)		((T *) xcalloc (1, (S)))
3615796c8dcSSimon Schubert #define XDUPVAR(T, P, S1, S2)	((T *) xmemdup ((P), (S1), (S2)))
3625796c8dcSSimon Schubert #define XRESIZEVAR(T, P, S)	((T *) xrealloc ((P), (S)))
3635796c8dcSSimon Schubert 
3645796c8dcSSimon Schubert /* Type-safe obstack allocator.  */
3655796c8dcSSimon Schubert 
3665796c8dcSSimon Schubert #define XOBNEW(O, T)		((T *) obstack_alloc ((O), sizeof (T)))
3675796c8dcSSimon Schubert #define XOBNEWVEC(O, T, N)	((T *) obstack_alloc ((O), sizeof (T) * (N)))
3685796c8dcSSimon Schubert #define XOBNEWVAR(O, T, S)	((T *) obstack_alloc ((O), (S)))
3695796c8dcSSimon Schubert #define XOBFINISH(O, T)         ((T) obstack_finish ((O)))
3705796c8dcSSimon Schubert 
3715796c8dcSSimon Schubert /* hex character manipulation routines */
3725796c8dcSSimon Schubert 
3735796c8dcSSimon Schubert #define _hex_array_size 256
3745796c8dcSSimon Schubert #define _hex_bad	99
3755796c8dcSSimon Schubert extern const unsigned char _hex_value[_hex_array_size];
3765796c8dcSSimon Schubert extern void hex_init (void);
3775796c8dcSSimon Schubert #define hex_p(c)	(hex_value (c) != _hex_bad)
3785796c8dcSSimon Schubert /* If you change this, note well: Some code relies on side effects in
3795796c8dcSSimon Schubert    the argument being performed exactly once.  */
3805796c8dcSSimon Schubert #define hex_value(c)	((unsigned int) _hex_value[(unsigned char) (c)])
3815796c8dcSSimon Schubert 
3825796c8dcSSimon Schubert /* Flags for pex_init.  These are bits to be or'ed together.  */
3835796c8dcSSimon Schubert 
3845796c8dcSSimon Schubert /* Record subprocess times, if possible.  */
3855796c8dcSSimon Schubert #define PEX_RECORD_TIMES	0x1
3865796c8dcSSimon Schubert 
3875796c8dcSSimon Schubert /* Use pipes for communication between processes, if possible.  */
3885796c8dcSSimon Schubert #define PEX_USE_PIPES		0x2
3895796c8dcSSimon Schubert 
3905796c8dcSSimon Schubert /* Save files used for communication between processes.  */
3915796c8dcSSimon Schubert #define PEX_SAVE_TEMPS		0x4
3925796c8dcSSimon Schubert 
3935796c8dcSSimon Schubert /* Prepare to execute one or more programs, with standard output of
3945796c8dcSSimon Schubert    each program fed to standard input of the next.
3955796c8dcSSimon Schubert    FLAGS	As above.
3965796c8dcSSimon Schubert    PNAME	The name of the program to report in error messages.
3975796c8dcSSimon Schubert    TEMPBASE	A base name to use for temporary files; may be NULL to
3985796c8dcSSimon Schubert    		use a random name.
3995796c8dcSSimon Schubert    Returns NULL on error.  */
4005796c8dcSSimon Schubert 
4015796c8dcSSimon Schubert extern struct pex_obj *pex_init (int flags, const char *pname,
4025796c8dcSSimon Schubert 				 const char *tempbase);
4035796c8dcSSimon Schubert 
4045796c8dcSSimon Schubert /* Flags for pex_run.  These are bits to be or'ed together.  */
4055796c8dcSSimon Schubert 
4065796c8dcSSimon Schubert /* Last program in pipeline.  Standard output of program goes to
4075796c8dcSSimon Schubert    OUTNAME, or, if OUTNAME is NULL, to standard output of caller.  Do
4085796c8dcSSimon Schubert    not set this if you want to call pex_read_output.  After this is
4095796c8dcSSimon Schubert    set, pex_run may no longer be called with the same struct
4105796c8dcSSimon Schubert    pex_obj.  */
4115796c8dcSSimon Schubert #define PEX_LAST		0x1
4125796c8dcSSimon Schubert 
4135796c8dcSSimon Schubert /* Search for program in executable search path.  */
4145796c8dcSSimon Schubert #define PEX_SEARCH		0x2
4155796c8dcSSimon Schubert 
4165796c8dcSSimon Schubert /* OUTNAME is a suffix.  */
4175796c8dcSSimon Schubert #define PEX_SUFFIX		0x4
4185796c8dcSSimon Schubert 
4195796c8dcSSimon Schubert /* Send program's standard error to standard output.  */
4205796c8dcSSimon Schubert #define PEX_STDERR_TO_STDOUT	0x8
4215796c8dcSSimon Schubert 
4225796c8dcSSimon Schubert /* Input file should be opened in binary mode.  This flag is ignored
4235796c8dcSSimon Schubert    on Unix.  */
4245796c8dcSSimon Schubert #define PEX_BINARY_INPUT	0x10
4255796c8dcSSimon Schubert 
4265796c8dcSSimon Schubert /* Output file should be opened in binary mode.  This flag is ignored
4275796c8dcSSimon Schubert    on Unix.  For proper behaviour PEX_BINARY_INPUT and
4285796c8dcSSimon Schubert    PEX_BINARY_OUTPUT have to match appropriately--i.e., a call using
4295796c8dcSSimon Schubert    PEX_BINARY_OUTPUT should be followed by a call using
4305796c8dcSSimon Schubert    PEX_BINARY_INPUT.  */
4315796c8dcSSimon Schubert #define PEX_BINARY_OUTPUT	0x20
4325796c8dcSSimon Schubert 
4335796c8dcSSimon Schubert /* Capture stderr to a pipe.  The output can be read by
4345796c8dcSSimon Schubert    calling pex_read_err and reading from the returned
4355796c8dcSSimon Schubert    FILE object.  This flag may be specified only for
4365796c8dcSSimon Schubert    the last program in a pipeline.
4375796c8dcSSimon Schubert 
4385796c8dcSSimon Schubert    This flag is supported only on Unix and Windows.  */
4395796c8dcSSimon Schubert #define PEX_STDERR_TO_PIPE	0x40
4405796c8dcSSimon Schubert 
4415796c8dcSSimon Schubert /* Capture stderr in binary mode.  This flag is ignored
4425796c8dcSSimon Schubert    on Unix.  */
4435796c8dcSSimon Schubert #define PEX_BINARY_ERROR	0x80
4445796c8dcSSimon Schubert 
4455796c8dcSSimon Schubert 
4465796c8dcSSimon Schubert /* Execute one program.  Returns NULL on success.  On error returns an
4475796c8dcSSimon Schubert    error string (typically just the name of a system call); the error
4485796c8dcSSimon Schubert    string is statically allocated.
4495796c8dcSSimon Schubert 
4505796c8dcSSimon Schubert    OBJ		Returned by pex_init.
4515796c8dcSSimon Schubert 
4525796c8dcSSimon Schubert    FLAGS	As above.
4535796c8dcSSimon Schubert 
4545796c8dcSSimon Schubert    EXECUTABLE	The program to execute.
4555796c8dcSSimon Schubert 
4565796c8dcSSimon Schubert    ARGV		NULL terminated array of arguments to pass to the program.
4575796c8dcSSimon Schubert 
4585796c8dcSSimon Schubert    OUTNAME	Sets the output file name as follows:
4595796c8dcSSimon Schubert 
4605796c8dcSSimon Schubert 		PEX_SUFFIX set (OUTNAME may not be NULL):
4615796c8dcSSimon Schubert 		  TEMPBASE parameter to pex_init not NULL:
4625796c8dcSSimon Schubert 		    Output file name is the concatenation of TEMPBASE
4635796c8dcSSimon Schubert 		    and OUTNAME.
4645796c8dcSSimon Schubert 		  TEMPBASE is NULL:
4655796c8dcSSimon Schubert 		    Output file name is a random file name ending in
4665796c8dcSSimon Schubert 		    OUTNAME.
4675796c8dcSSimon Schubert 		PEX_SUFFIX not set:
4685796c8dcSSimon Schubert 		  OUTNAME not NULL:
4695796c8dcSSimon Schubert 		    Output file name is OUTNAME.
4705796c8dcSSimon Schubert 		  OUTNAME NULL, TEMPBASE not NULL:
4715796c8dcSSimon Schubert 		    Output file name is randomly chosen using
4725796c8dcSSimon Schubert 		    TEMPBASE.
4735796c8dcSSimon Schubert 		  OUTNAME NULL, TEMPBASE NULL:
4745796c8dcSSimon Schubert 		    Output file name is randomly chosen.
4755796c8dcSSimon Schubert 
4765796c8dcSSimon Schubert 		If PEX_LAST is not set, the output file name is the
4775796c8dcSSimon Schubert    		name to use for a temporary file holding stdout, if
4785796c8dcSSimon Schubert    		any (there will not be a file if PEX_USE_PIPES is set
4795796c8dcSSimon Schubert    		and the system supports pipes).  If a file is used, it
4805796c8dcSSimon Schubert    		will be removed when no longer needed unless
4815796c8dcSSimon Schubert    		PEX_SAVE_TEMPS is set.
4825796c8dcSSimon Schubert 
4835796c8dcSSimon Schubert 		If PEX_LAST is set, and OUTNAME is not NULL, standard
4845796c8dcSSimon Schubert    		output is written to the output file name.  The file
4855796c8dcSSimon Schubert    		will not be removed.  If PEX_LAST and PEX_SUFFIX are
4865796c8dcSSimon Schubert    		both set, TEMPBASE may not be NULL.
4875796c8dcSSimon Schubert 
4885796c8dcSSimon Schubert    ERRNAME	If not NULL, this is the name of a file to which
4895796c8dcSSimon Schubert 		standard error is written.  If NULL, standard error of
4905796c8dcSSimon Schubert 		the program is standard error of the caller.
4915796c8dcSSimon Schubert 
4925796c8dcSSimon Schubert    ERR		On an error return, *ERR is set to an errno value, or
4935796c8dcSSimon Schubert    		to 0 if there is no relevant errno.
4945796c8dcSSimon Schubert */
4955796c8dcSSimon Schubert 
4965796c8dcSSimon Schubert extern const char *pex_run (struct pex_obj *obj, int flags,
4975796c8dcSSimon Schubert 			    const char *executable, char * const *argv,
4985796c8dcSSimon Schubert 			    const char *outname, const char *errname,
4995796c8dcSSimon Schubert 			    int *err);
5005796c8dcSSimon Schubert 
5015796c8dcSSimon Schubert /* As for pex_run (), but takes an extra parameter to enable the
5025796c8dcSSimon Schubert    environment for the child process to be specified.
5035796c8dcSSimon Schubert 
5045796c8dcSSimon Schubert    ENV		The environment for the child process, specified as
5055796c8dcSSimon Schubert 		an array of character pointers.  Each element of the
5065796c8dcSSimon Schubert 		array should point to a string of the form VAR=VALUE,
5075796c8dcSSimon Schubert                 with the exception of the last element which must be
5085796c8dcSSimon Schubert                 a null pointer.
5095796c8dcSSimon Schubert */
5105796c8dcSSimon Schubert 
5115796c8dcSSimon Schubert extern const char *pex_run_in_environment (struct pex_obj *obj, int flags,
5125796c8dcSSimon Schubert 			                   const char *executable,
5135796c8dcSSimon Schubert                                            char * const *argv,
5145796c8dcSSimon Schubert                                            char * const *env,
5155796c8dcSSimon Schubert               	          		   const char *outname,
5165796c8dcSSimon Schubert 					   const char *errname, int *err);
5175796c8dcSSimon Schubert 
5185796c8dcSSimon Schubert /* Return a stream for a temporary file to pass to the first program
5195796c8dcSSimon Schubert    in the pipeline as input.  The file name is chosen as for pex_run.
5205796c8dcSSimon Schubert    pex_run closes the file automatically; don't close it yourself.  */
5215796c8dcSSimon Schubert 
5225796c8dcSSimon Schubert extern FILE *pex_input_file (struct pex_obj *obj, int flags,
5235796c8dcSSimon Schubert                              const char *in_name);
5245796c8dcSSimon Schubert 
5255796c8dcSSimon Schubert /* Return a stream for a pipe connected to the standard input of the
5265796c8dcSSimon Schubert    first program in the pipeline.  You must have passed
5275796c8dcSSimon Schubert    `PEX_USE_PIPES' to `pex_init'.  Close the returned stream
5285796c8dcSSimon Schubert    yourself.  */
5295796c8dcSSimon Schubert 
5305796c8dcSSimon Schubert extern FILE *pex_input_pipe (struct pex_obj *obj, int binary);
5315796c8dcSSimon Schubert 
5325796c8dcSSimon Schubert /* Read the standard output of the last program to be executed.
5335796c8dcSSimon Schubert    pex_run can not be called after this.  BINARY should be non-zero if
5345796c8dcSSimon Schubert    the file should be opened in binary mode; this is ignored on Unix.
5355796c8dcSSimon Schubert    Returns NULL on error.  Don't call fclose on the returned FILE; it
5365796c8dcSSimon Schubert    will be closed by pex_free.  */
5375796c8dcSSimon Schubert 
5385796c8dcSSimon Schubert extern FILE *pex_read_output (struct pex_obj *, int binary);
5395796c8dcSSimon Schubert 
5405796c8dcSSimon Schubert /* Read the standard error of the last program to be executed.
5415796c8dcSSimon Schubert    pex_run can not be called after this.  BINARY should be non-zero if
5425796c8dcSSimon Schubert    the file should be opened in binary mode; this is ignored on Unix.
5435796c8dcSSimon Schubert    Returns NULL on error.  Don't call fclose on the returned FILE; it
5445796c8dcSSimon Schubert    will be closed by pex_free.  */
5455796c8dcSSimon Schubert 
5465796c8dcSSimon Schubert extern FILE *pex_read_err (struct pex_obj *, int binary);
5475796c8dcSSimon Schubert 
5485796c8dcSSimon Schubert /* Return exit status of all programs in VECTOR.  COUNT indicates the
5495796c8dcSSimon Schubert    size of VECTOR.  The status codes in the vector are in the order of
5505796c8dcSSimon Schubert    the calls to pex_run.  Returns 0 on error, 1 on success.  */
5515796c8dcSSimon Schubert 
5525796c8dcSSimon Schubert extern int pex_get_status (struct pex_obj *, int count, int *vector);
5535796c8dcSSimon Schubert 
5545796c8dcSSimon Schubert /* Return times of all programs in VECTOR.  COUNT indicates the size
5555796c8dcSSimon Schubert    of VECTOR.  struct pex_time is really just struct timeval, but that
5565796c8dcSSimon Schubert    is not portable to all systems.  Returns 0 on error, 1 on
5575796c8dcSSimon Schubert    success.  */
5585796c8dcSSimon Schubert 
5595796c8dcSSimon Schubert struct pex_time
5605796c8dcSSimon Schubert {
5615796c8dcSSimon Schubert   unsigned long user_seconds;
5625796c8dcSSimon Schubert   unsigned long user_microseconds;
5635796c8dcSSimon Schubert   unsigned long system_seconds;
5645796c8dcSSimon Schubert   unsigned long system_microseconds;
5655796c8dcSSimon Schubert };
5665796c8dcSSimon Schubert 
5675796c8dcSSimon Schubert extern int pex_get_times (struct pex_obj *, int count,
5685796c8dcSSimon Schubert 			  struct pex_time *vector);
5695796c8dcSSimon Schubert 
5705796c8dcSSimon Schubert /* Clean up a pex_obj.  If you have not called pex_get_times or
5715796c8dcSSimon Schubert    pex_get_status, this will try to kill the subprocesses.  */
5725796c8dcSSimon Schubert 
5735796c8dcSSimon Schubert extern void pex_free (struct pex_obj *);
5745796c8dcSSimon Schubert 
5755796c8dcSSimon Schubert /* Just execute one program.  Return value is as for pex_run.
5765796c8dcSSimon Schubert    FLAGS	Combination of PEX_SEARCH and PEX_STDERR_TO_STDOUT.
5775796c8dcSSimon Schubert    EXECUTABLE	As for pex_run.
5785796c8dcSSimon Schubert    ARGV		As for pex_run.
5795796c8dcSSimon Schubert    PNAME	As for pex_init.
5805796c8dcSSimon Schubert    OUTNAME	As for pex_run when PEX_LAST is set.
5815796c8dcSSimon Schubert    ERRNAME	As for pex_run.
5825796c8dcSSimon Schubert    STATUS	Set to exit status on success.
5835796c8dcSSimon Schubert    ERR		As for pex_run.
5845796c8dcSSimon Schubert */
5855796c8dcSSimon Schubert 
5865796c8dcSSimon Schubert extern const char *pex_one (int flags, const char *executable,
5875796c8dcSSimon Schubert 			    char * const *argv, const char *pname,
5885796c8dcSSimon Schubert 			    const char *outname, const char *errname,
5895796c8dcSSimon Schubert 			    int *status, int *err);
5905796c8dcSSimon Schubert 
5915796c8dcSSimon Schubert /* pexecute and pwait are the old pexecute interface, still here for
5925796c8dcSSimon Schubert    backward compatibility.  Don't use these for new code.  Instead,
5935796c8dcSSimon Schubert    use pex_init/pex_run/pex_get_status/pex_free, or pex_one.  */
5945796c8dcSSimon Schubert 
5955796c8dcSSimon Schubert /* Definitions used by the pexecute routine.  */
5965796c8dcSSimon Schubert 
5975796c8dcSSimon Schubert #define PEXECUTE_FIRST   1
5985796c8dcSSimon Schubert #define PEXECUTE_LAST    2
5995796c8dcSSimon Schubert #define PEXECUTE_ONE     (PEXECUTE_FIRST + PEXECUTE_LAST)
6005796c8dcSSimon Schubert #define PEXECUTE_SEARCH  4
6015796c8dcSSimon Schubert #define PEXECUTE_VERBOSE 8
6025796c8dcSSimon Schubert 
6035796c8dcSSimon Schubert /* Execute a program.  */
6045796c8dcSSimon Schubert 
6055796c8dcSSimon Schubert extern int pexecute (const char *, char * const *, const char *,
6065796c8dcSSimon Schubert                      const char *, char **, char **, int);
6075796c8dcSSimon Schubert 
6085796c8dcSSimon Schubert /* Wait for pexecute to finish.  */
6095796c8dcSSimon Schubert 
6105796c8dcSSimon Schubert extern int pwait (int, int *, int);
6115796c8dcSSimon Schubert 
6125796c8dcSSimon Schubert #if !HAVE_DECL_ASPRINTF
6135796c8dcSSimon Schubert /* Like sprintf but provides a pointer to malloc'd storage, which must
6145796c8dcSSimon Schubert    be freed by the caller.  */
6155796c8dcSSimon Schubert 
6165796c8dcSSimon Schubert extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2;
6175796c8dcSSimon Schubert #endif
6185796c8dcSSimon Schubert 
6195796c8dcSSimon Schubert #if !HAVE_DECL_VASPRINTF
6205796c8dcSSimon Schubert /* Like vsprintf but provides a pointer to malloc'd storage, which
6215796c8dcSSimon Schubert    must be freed by the caller.  */
6225796c8dcSSimon Schubert 
6235796c8dcSSimon Schubert extern int vasprintf (char **, const char *, va_list) ATTRIBUTE_PRINTF(2,0);
6245796c8dcSSimon Schubert #endif
6255796c8dcSSimon Schubert 
6265796c8dcSSimon Schubert #if defined(HAVE_DECL_SNPRINTF) && !HAVE_DECL_SNPRINTF
6275796c8dcSSimon Schubert /* Like sprintf but prints at most N characters.  */
6285796c8dcSSimon Schubert extern int snprintf (char *, size_t, const char *, ...) ATTRIBUTE_PRINTF_3;
6295796c8dcSSimon Schubert #endif
6305796c8dcSSimon Schubert 
6315796c8dcSSimon Schubert #if defined(HAVE_DECL_VSNPRINTF) && !HAVE_DECL_VSNPRINTF
6325796c8dcSSimon Schubert /* Like vsprintf but prints at most N characters.  */
6335796c8dcSSimon Schubert extern int vsnprintf (char *, size_t, const char *, va_list) ATTRIBUTE_PRINTF(3,0);
6345796c8dcSSimon Schubert #endif
6355796c8dcSSimon Schubert 
6365796c8dcSSimon Schubert #if defined(HAVE_DECL_STRVERSCMP) && !HAVE_DECL_STRVERSCMP
6375796c8dcSSimon Schubert /* Compare version strings.  */
6385796c8dcSSimon Schubert extern int strverscmp (const char *, const char *);
6395796c8dcSSimon Schubert #endif
6405796c8dcSSimon Schubert 
641c50c785cSJohn Marino /* Set the title of a process */
642c50c785cSJohn Marino extern void setproctitle (const char *name, ...);
643c50c785cSJohn Marino 
644a45ae5f8SJohn Marino /* Increase stack limit if possible.  */
645a45ae5f8SJohn Marino extern void stack_limit_increase (unsigned long);
646a45ae5f8SJohn Marino 
6475796c8dcSSimon Schubert #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
6485796c8dcSSimon Schubert 
6495796c8dcSSimon Schubert /* Drastically simplified alloca configurator.  If we're using GCC,
6505796c8dcSSimon Schubert    we use __builtin_alloca; otherwise we use the C alloca.  The C
6515796c8dcSSimon Schubert    alloca is always available.  You can override GCC by defining
6525796c8dcSSimon Schubert    USE_C_ALLOCA yourself.  The canonical autoconf macro C_ALLOCA is
6535796c8dcSSimon Schubert    also set/unset as it is often used to indicate whether code needs
6545796c8dcSSimon Schubert    to call alloca(0).  */
6555796c8dcSSimon Schubert extern void *C_alloca (size_t) ATTRIBUTE_MALLOC;
6565796c8dcSSimon Schubert #undef alloca
6575796c8dcSSimon Schubert #if GCC_VERSION >= 2000 && !defined USE_C_ALLOCA
6585796c8dcSSimon Schubert # define alloca(x) __builtin_alloca(x)
6595796c8dcSSimon Schubert # undef C_ALLOCA
6605796c8dcSSimon Schubert # define ASTRDUP(X) \
6615796c8dcSSimon Schubert   (__extension__ ({ const char *const libiberty_optr = (X); \
6625796c8dcSSimon Schubert    const unsigned long libiberty_len = strlen (libiberty_optr) + 1; \
6635796c8dcSSimon Schubert    char *const libiberty_nptr = (char *const) alloca (libiberty_len); \
6645796c8dcSSimon Schubert    (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len); }))
6655796c8dcSSimon Schubert #else
6665796c8dcSSimon Schubert # define alloca(x) C_alloca(x)
6675796c8dcSSimon Schubert # undef USE_C_ALLOCA
6685796c8dcSSimon Schubert # define USE_C_ALLOCA 1
6695796c8dcSSimon Schubert # undef C_ALLOCA
6705796c8dcSSimon Schubert # define C_ALLOCA 1
6715796c8dcSSimon Schubert extern const char *libiberty_optr;
6725796c8dcSSimon Schubert extern char *libiberty_nptr;
6735796c8dcSSimon Schubert extern unsigned long libiberty_len;
6745796c8dcSSimon Schubert # define ASTRDUP(X) \
6755796c8dcSSimon Schubert   (libiberty_optr = (X), \
6765796c8dcSSimon Schubert    libiberty_len = strlen (libiberty_optr) + 1, \
6775796c8dcSSimon Schubert    libiberty_nptr = (char *) alloca (libiberty_len), \
6785796c8dcSSimon Schubert    (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len))
6795796c8dcSSimon Schubert #endif
6805796c8dcSSimon Schubert 
6815796c8dcSSimon Schubert #ifdef __cplusplus
6825796c8dcSSimon Schubert }
6835796c8dcSSimon Schubert #endif
6845796c8dcSSimon Schubert 
6855796c8dcSSimon Schubert 
6865796c8dcSSimon Schubert #endif /* ! defined (LIBIBERTY_H) */
687