libiberty.h revision 77298
133965Sjdp/* Function declarations for libiberty.
233965Sjdp   Written by Cygnus Support, 1994.
333965Sjdp
433965Sjdp   The libiberty library provides a number of functions which are
533965Sjdp   missing on some operating systems.  We do not declare those here,
633965Sjdp   to avoid conflicts with the system header files on operating
733965Sjdp   systems that do support those functions.  In this file we only
833965Sjdp   declare those functions which are specific to libiberty.  */
933965Sjdp
1033965Sjdp#ifndef LIBIBERTY_H
1133965Sjdp#define LIBIBERTY_H
1233965Sjdp
1338889Sjdp#ifdef __cplusplus
1438889Sjdpextern "C" {
1538889Sjdp#endif
1638889Sjdp
1733965Sjdp#include "ansidecl.h"
1833965Sjdp
1977298Sobrien#ifdef ANSI_PROTOTYPES
2077298Sobrien/* Get a definition for size_t.  */
2177298Sobrien#include <stddef.h>
2277298Sobrien/* Get a definition for va_list.  */
2377298Sobrien#include <stdarg.h>
2477298Sobrien#endif
2577298Sobrien
2633965Sjdp/* Build an argument vector from a string.  Allocates memory using
2733965Sjdp   malloc.  Use freeargv to free the vector.  */
2833965Sjdp
2960484Sobrienextern char **buildargv PARAMS ((char *)) ATTRIBUTE_MALLOC;
3033965Sjdp
3133965Sjdp/* Free a vector returned by buildargv.  */
3233965Sjdp
3333965Sjdpextern void freeargv PARAMS ((char **));
3433965Sjdp
3538889Sjdp/* Duplicate an argument vector. Allocates memory using malloc.  Use
3638889Sjdp   freeargv to free the vector.  */
3738889Sjdp
3860484Sobrienextern char **dupargv PARAMS ((char **)) ATTRIBUTE_MALLOC;
3938889Sjdp
4038889Sjdp
4133965Sjdp/* Return the last component of a path name.  Note that we can't use a
4233965Sjdp   prototype here because the parameter is declared inconsistently
4333965Sjdp   across different systems, sometimes as "char *" and sometimes as
4433965Sjdp   "const char *" */
4533965Sjdp
4677298Sobrien/* HAVE_DECL_* is a three-state macro: undefined, 0 or 1.  If it is
4777298Sobrien   undefined, we haven't run the autoconf check so provide the
4877298Sobrien   declaration without arguments.  If it is 0, we checked and failed
4977298Sobrien   to find the declaration so provide a fully prototyped one.  If it
5077298Sobrien   is 1, we found it so don't provide any declaration at all.  */
5177298Sobrien#if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || (defined (HAVE_DECL_BASENAME) && !HAVE_DECL_BASENAME)
5233965Sjdpextern char *basename PARAMS ((const char *));
5333965Sjdp#else
5477298Sobrien# if !defined (HAVE_DECL_BASENAME)
5533965Sjdpextern char *basename ();
5677298Sobrien# endif
5733965Sjdp#endif
5833965Sjdp
5933965Sjdp/* Concatenate an arbitrary number of strings, up to (char *) NULL.
6033965Sjdp   Allocates memory using xmalloc.  */
6133965Sjdp
6260484Sobrienextern char *concat PARAMS ((const char *, ...)) ATTRIBUTE_MALLOC;
6333965Sjdp
6433965Sjdp/* Check whether two file descriptors refer to the same file.  */
6533965Sjdp
6633965Sjdpextern int fdmatch PARAMS ((int fd1, int fd2));
6733965Sjdp
6860484Sobrien/* Get the working directory.  The result is cached, so don't call
6960484Sobrien   chdir() between calls to getpwd().  */
7060484Sobrien
7160484Sobrienextern char * getpwd PARAMS ((void));
7260484Sobrien
7333965Sjdp/* Get the amount of time the process has run, in microseconds.  */
7433965Sjdp
7533965Sjdpextern long get_run_time PARAMS ((void));
7633965Sjdp
7733965Sjdp/* Choose a temporary directory to use for scratch files.  */
7833965Sjdp
7960484Sobrienextern char *choose_temp_base PARAMS ((void)) ATTRIBUTE_MALLOC;
8033965Sjdp
8160484Sobrien/* Return a temporary file name or NULL if unable to create one.  */
8260484Sobrien
8360484Sobrienextern char *make_temp_file PARAMS ((const char *)) ATTRIBUTE_MALLOC;
8460484Sobrien
8533965Sjdp/* Allocate memory filled with spaces.  Allocates using malloc.  */
8633965Sjdp
8733965Sjdpextern const char *spaces PARAMS ((int count));
8833965Sjdp
8933965Sjdp/* Return the maximum error number for which strerror will return a
9033965Sjdp   string.  */
9133965Sjdp
9233965Sjdpextern int errno_max PARAMS ((void));
9333965Sjdp
9433965Sjdp/* Return the name of an errno value (e.g., strerrno (EINVAL) returns
9533965Sjdp   "EINVAL").  */
9633965Sjdp
9733965Sjdpextern const char *strerrno PARAMS ((int));
9833965Sjdp
9933965Sjdp/* Given the name of an errno value, return the value.  */
10033965Sjdp
10133965Sjdpextern int strtoerrno PARAMS ((const char *));
10233965Sjdp
10333965Sjdp/* ANSI's strerror(), but more robust.  */
10433965Sjdp
10533965Sjdpextern char *xstrerror PARAMS ((int));
10633965Sjdp
10733965Sjdp/* Return the maximum signal number for which strsignal will return a
10833965Sjdp   string.  */
10933965Sjdp
11033965Sjdpextern int signo_max PARAMS ((void));
11133965Sjdp
11233965Sjdp/* Return a signal message string for a signal number
11333965Sjdp   (e.g., strsignal (SIGHUP) returns something like "Hangup").  */
11433965Sjdp/* This is commented out as it can conflict with one in system headers.
11533965Sjdp   We still document its existence though.  */
11633965Sjdp
11733965Sjdp/*extern const char *strsignal PARAMS ((int));*/
11833965Sjdp
11933965Sjdp/* Return the name of a signal number (e.g., strsigno (SIGHUP) returns
12033965Sjdp   "SIGHUP").  */
12133965Sjdp
12233965Sjdpextern const char *strsigno PARAMS ((int));
12333965Sjdp
12433965Sjdp/* Given the name of a signal, return its number.  */
12533965Sjdp
12633965Sjdpextern int strtosigno PARAMS ((const char *));
12733965Sjdp
12833965Sjdp/* Register a function to be run by xexit.  Returns 0 on success.  */
12933965Sjdp
13033965Sjdpextern int xatexit PARAMS ((void (*fn) (void)));
13133965Sjdp
13233965Sjdp/* Exit, calling all the functions registered with xatexit.  */
13333965Sjdp
13460484Sobrienextern void xexit PARAMS ((int status)) ATTRIBUTE_NORETURN;
13533965Sjdp
13633965Sjdp/* Set the program name used by xmalloc.  */
13733965Sjdp
13833965Sjdpextern void xmalloc_set_program_name PARAMS ((const char *));
13933965Sjdp
14077298Sobrien/* Report an allocation failure.  */
14177298Sobrienextern void xmalloc_failed PARAMS ((size_t)) ATTRIBUTE_NORETURN;
14277298Sobrien
14333965Sjdp/* Allocate memory without fail.  If malloc fails, this will print a
14433965Sjdp   message to stderr (using the name set by xmalloc_set_program_name,
14533965Sjdp   if any) and then call xexit.  */
14633965Sjdp
14760484Sobrienextern PTR xmalloc PARAMS ((size_t)) ATTRIBUTE_MALLOC;
14833965Sjdp
14960484Sobrien/* Reallocate memory without fail.  This works like xmalloc.  Note,
15060484Sobrien   realloc type functions are not suitable for attribute malloc since
15160484Sobrien   they may return the same address across multiple calls. */
15233965Sjdp
15360484Sobrienextern PTR xrealloc PARAMS ((PTR, size_t));
15460484Sobrien
15560484Sobrien/* Allocate memory without fail and set it to zero.  This works like
15633965Sjdp   xmalloc.  */
15733965Sjdp
15860484Sobrienextern PTR xcalloc PARAMS ((size_t, size_t)) ATTRIBUTE_MALLOC;
15933965Sjdp
16033965Sjdp/* Copy a string into a memory buffer without fail.  */
16133965Sjdp
16260484Sobrienextern char *xstrdup PARAMS ((const char *)) ATTRIBUTE_MALLOC;
16333965Sjdp
16460484Sobrien/* Copy an existing memory buffer to a new memory buffer without fail.  */
16560484Sobrien
16660484Sobrienextern PTR xmemdup PARAMS ((const PTR, size_t, size_t)) ATTRIBUTE_MALLOC;
16760484Sobrien
16833965Sjdp/* hex character manipulation routines */
16933965Sjdp
17033965Sjdp#define _hex_array_size 256
17133965Sjdp#define _hex_bad	99
17233965Sjdpextern char _hex_value[_hex_array_size];
17333965Sjdpextern void hex_init PARAMS ((void));
17433965Sjdp#define hex_p(c)	(hex_value (c) != _hex_bad)
17533965Sjdp/* If you change this, note well: Some code relies on side effects in
17633965Sjdp   the argument being performed exactly once.  */
17733965Sjdp#define hex_value(c)	(_hex_value[(unsigned char) (c)])
17833965Sjdp
17938889Sjdp/* Definitions used by the pexecute routine.  */
18038889Sjdp
18138889Sjdp#define PEXECUTE_FIRST   1
18238889Sjdp#define PEXECUTE_LAST    2
18338889Sjdp#define PEXECUTE_ONE     (PEXECUTE_FIRST + PEXECUTE_LAST)
18438889Sjdp#define PEXECUTE_SEARCH  4
18538889Sjdp#define PEXECUTE_VERBOSE 8
18638889Sjdp
18738889Sjdp/* Execute a program.  */
18838889Sjdp
18938889Sjdpextern int pexecute PARAMS ((const char *, char * const *, const char *,
19038889Sjdp			    const char *, char **, char **, int));
19138889Sjdp
19238889Sjdp/* Wait for pexecute to finish.  */
19338889Sjdp
19438889Sjdpextern int pwait PARAMS ((int, int *, int));
19538889Sjdp
19660484Sobrien/* Like sprintf but provides a pointer to malloc'd storage, which must
19760484Sobrien   be freed by the caller.  */
19860484Sobrien
19960484Sobrienextern int asprintf PARAMS ((char **, const char *, ...)) ATTRIBUTE_PRINTF_2;
20060484Sobrien
20160484Sobrien/* Like vsprintf but provides a pointer to malloc'd storage, which
20260484Sobrien   must be freed by the caller.  */
20360484Sobrien
20460484Sobrienextern int vasprintf PARAMS ((char **, const char *, va_list))
20560484Sobrien  ATTRIBUTE_PRINTF(2,0);
20660484Sobrien
20777298Sobrien#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
20877298Sobrien
20938889Sjdp#ifdef __cplusplus
21038889Sjdp}
21138889Sjdp#endif
21238889Sjdp
21338889Sjdp
21433965Sjdp#endif /* ! defined (LIBIBERTY_H) */
215