12159047fSniklas /* Function declarations for libiberty. 2*b55d4692Sfgsch 3*b55d4692Sfgsch Copyright 2001 Free Software Foundation, Inc. 4*b55d4692Sfgsch 5*b55d4692Sfgsch Note - certain prototypes declared in this header file are for 6*b55d4692Sfgsch functions whoes implementation copyright does not belong to the 7*b55d4692Sfgsch FSF. Those prototypes are present in this file for reference 8*b55d4692Sfgsch purposes only and their presence in this file should not construed 9*b55d4692Sfgsch as an indication of ownership by the FSF of the implementation of 10*b55d4692Sfgsch those functions in any way or form whatsoever. 11*b55d4692Sfgsch 12*b55d4692Sfgsch This program is free software; you can redistribute it and/or modify 13*b55d4692Sfgsch it under the terms of the GNU General Public License as published by 14*b55d4692Sfgsch the Free Software Foundation; either version 2, or (at your option) 15*b55d4692Sfgsch any later version. 16*b55d4692Sfgsch 17*b55d4692Sfgsch This program is distributed in the hope that it will be useful, 18*b55d4692Sfgsch but WITHOUT ANY WARRANTY; without even the implied warranty of 19*b55d4692Sfgsch MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20*b55d4692Sfgsch GNU General Public License for more details. 21*b55d4692Sfgsch 22*b55d4692Sfgsch You should have received a copy of the GNU General Public License 23*b55d4692Sfgsch along with this program; if not, write to the Free Software 24*b55d4692Sfgsch Foundation, Inc., 59 Temple Place - Suite 330, 25*b55d4692Sfgsch Boston, MA 02111-1307, USA. 26*b55d4692Sfgsch 272159047fSniklas Written by Cygnus Support, 1994. 282159047fSniklas 292159047fSniklas The libiberty library provides a number of functions which are 302159047fSniklas missing on some operating systems. We do not declare those here, 312159047fSniklas to avoid conflicts with the system header files on operating 322159047fSniklas systems that do support those functions. In this file we only 332159047fSniklas declare those functions which are specific to libiberty. */ 342159047fSniklas 352159047fSniklas #ifndef LIBIBERTY_H 362159047fSniklas #define LIBIBERTY_H 372159047fSniklas 38b305b0f1Sespie #ifdef __cplusplus 39b305b0f1Sespie extern "C" { 40b305b0f1Sespie #endif 41b305b0f1Sespie 422159047fSniklas #include "ansidecl.h" 432159047fSniklas 44*b55d4692Sfgsch #ifdef ANSI_PROTOTYPES 45*b55d4692Sfgsch /* Get a definition for size_t. */ 46*b55d4692Sfgsch #include <stddef.h> 47*b55d4692Sfgsch /* Get a definition for va_list. */ 48*b55d4692Sfgsch #include <stdarg.h> 49*b55d4692Sfgsch #endif 50*b55d4692Sfgsch 512159047fSniklas /* Build an argument vector from a string. Allocates memory using 522159047fSniklas malloc. Use freeargv to free the vector. */ 532159047fSniklas 54b305b0f1Sespie extern char **buildargv PARAMS ((char *)) ATTRIBUTE_MALLOC; 552159047fSniklas 562159047fSniklas /* Free a vector returned by buildargv. */ 572159047fSniklas 582159047fSniklas extern void freeargv PARAMS ((char **)); 592159047fSniklas 60b305b0f1Sespie /* Duplicate an argument vector. Allocates memory using malloc. Use 61b305b0f1Sespie freeargv to free the vector. */ 62b305b0f1Sespie 63b305b0f1Sespie extern char **dupargv PARAMS ((char **)) ATTRIBUTE_MALLOC; 64b305b0f1Sespie 65b305b0f1Sespie 660c6d0228Sniklas /* Return the last component of a path name. Note that we can't use a 670c6d0228Sniklas prototype here because the parameter is declared inconsistently 680c6d0228Sniklas across different systems, sometimes as "char *" and sometimes as 690c6d0228Sniklas "const char *" */ 702159047fSniklas 71*b55d4692Sfgsch /* HAVE_DECL_* is a three-state macro: undefined, 0 or 1. If it is 72*b55d4692Sfgsch undefined, we haven't run the autoconf check so provide the 73*b55d4692Sfgsch declaration without arguments. If it is 0, we checked and failed 74*b55d4692Sfgsch to find the declaration so provide a fully prototyped one. If it 75*b55d4692Sfgsch is 1, we found it so don't provide any declaration at all. */ 76*b55d4692Sfgsch #if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || (defined (HAVE_DECL_BASENAME) && !HAVE_DECL_BASENAME) 77b305b0f1Sespie extern char *basename PARAMS ((const char *)); 78b305b0f1Sespie #else 79*b55d4692Sfgsch # if !defined (HAVE_DECL_BASENAME) 802159047fSniklas extern char *basename (); 81b305b0f1Sespie # endif 82*b55d4692Sfgsch #endif 832159047fSniklas 842159047fSniklas /* Concatenate an arbitrary number of strings, up to (char *) NULL. 852159047fSniklas Allocates memory using xmalloc. */ 862159047fSniklas 87b305b0f1Sespie extern char *concat PARAMS ((const char *, ...)) ATTRIBUTE_MALLOC; 882159047fSniklas 892159047fSniklas /* Check whether two file descriptors refer to the same file. */ 902159047fSniklas 912159047fSniklas extern int fdmatch PARAMS ((int fd1, int fd2)); 922159047fSniklas 93b305b0f1Sespie /* Get the working directory. The result is cached, so don't call 94b305b0f1Sespie chdir() between calls to getpwd(). */ 95b305b0f1Sespie 96b305b0f1Sespie extern char * getpwd PARAMS ((void)); 97b305b0f1Sespie 982159047fSniklas /* Get the amount of time the process has run, in microseconds. */ 992159047fSniklas 1002159047fSniklas extern long get_run_time PARAMS ((void)); 1012159047fSniklas 102b305b0f1Sespie /* Choose a temporary directory to use for scratch files. */ 103c88b1d6cSniklas 104b305b0f1Sespie extern char *choose_temp_base PARAMS ((void)) ATTRIBUTE_MALLOC; 105c88b1d6cSniklas 106b305b0f1Sespie /* Return a temporary file name or NULL if unable to create one. */ 107b305b0f1Sespie 108b305b0f1Sespie extern char *make_temp_file PARAMS ((const char *)) ATTRIBUTE_MALLOC; 109bc1ed23cSespie 1102159047fSniklas /* Allocate memory filled with spaces. Allocates using malloc. */ 1112159047fSniklas 1122159047fSniklas extern const char *spaces PARAMS ((int count)); 1132159047fSniklas 1142159047fSniklas /* Return the maximum error number for which strerror will return a 1152159047fSniklas string. */ 1162159047fSniklas 1172159047fSniklas extern int errno_max PARAMS ((void)); 1182159047fSniklas 1192159047fSniklas /* Return the name of an errno value (e.g., strerrno (EINVAL) returns 1202159047fSniklas "EINVAL"). */ 1212159047fSniklas 1222159047fSniklas extern const char *strerrno PARAMS ((int)); 1232159047fSniklas 1242159047fSniklas /* Given the name of an errno value, return the value. */ 1252159047fSniklas 1262159047fSniklas extern int strtoerrno PARAMS ((const char *)); 1272159047fSniklas 1282159047fSniklas /* ANSI's strerror(), but more robust. */ 1292159047fSniklas 1302159047fSniklas extern char *xstrerror PARAMS ((int)); 1312159047fSniklas 1322159047fSniklas /* Return the maximum signal number for which strsignal will return a 1332159047fSniklas string. */ 1342159047fSniklas 1352159047fSniklas extern int signo_max PARAMS ((void)); 1362159047fSniklas 1372159047fSniklas /* Return a signal message string for a signal number 1382159047fSniklas (e.g., strsignal (SIGHUP) returns something like "Hangup"). */ 1392159047fSniklas /* This is commented out as it can conflict with one in system headers. 1402159047fSniklas We still document its existence though. */ 1412159047fSniklas 1422159047fSniklas /*extern const char *strsignal PARAMS ((int));*/ 1432159047fSniklas 1442159047fSniklas /* Return the name of a signal number (e.g., strsigno (SIGHUP) returns 1452159047fSniklas "SIGHUP"). */ 1462159047fSniklas 1472159047fSniklas extern const char *strsigno PARAMS ((int)); 1482159047fSniklas 1492159047fSniklas /* Given the name of a signal, return its number. */ 1502159047fSniklas 1512159047fSniklas extern int strtosigno PARAMS ((const char *)); 1522159047fSniklas 1532159047fSniklas /* Register a function to be run by xexit. Returns 0 on success. */ 1542159047fSniklas 1552159047fSniklas extern int xatexit PARAMS ((void (*fn) (void))); 1562159047fSniklas 1572159047fSniklas /* Exit, calling all the functions registered with xatexit. */ 1582159047fSniklas 159b305b0f1Sespie extern void xexit PARAMS ((int status)) ATTRIBUTE_NORETURN; 1602159047fSniklas 1612159047fSniklas /* Set the program name used by xmalloc. */ 1622159047fSniklas 1632159047fSniklas extern void xmalloc_set_program_name PARAMS ((const char *)); 1642159047fSniklas 165*b55d4692Sfgsch /* Report an allocation failure. */ 166*b55d4692Sfgsch extern void xmalloc_failed PARAMS ((size_t)) ATTRIBUTE_NORETURN; 167*b55d4692Sfgsch 1682159047fSniklas /* Allocate memory without fail. If malloc fails, this will print a 1692159047fSniklas message to stderr (using the name set by xmalloc_set_program_name, 170e93f7393Sniklas if any) and then call xexit. */ 1712159047fSniklas 172b305b0f1Sespie extern PTR xmalloc PARAMS ((size_t)) ATTRIBUTE_MALLOC; 1732159047fSniklas 174b305b0f1Sespie /* Reallocate memory without fail. This works like xmalloc. Note, 175b305b0f1Sespie realloc type functions are not suitable for attribute malloc since 176b305b0f1Sespie they may return the same address across multiple calls. */ 1772159047fSniklas 178e93f7393Sniklas extern PTR xrealloc PARAMS ((PTR, size_t)); 1790c6d0228Sniklas 180b305b0f1Sespie /* Allocate memory without fail and set it to zero. This works like 181b305b0f1Sespie xmalloc. */ 182b305b0f1Sespie 183b305b0f1Sespie extern PTR xcalloc PARAMS ((size_t, size_t)) ATTRIBUTE_MALLOC; 184b305b0f1Sespie 185c88b1d6cSniklas /* Copy a string into a memory buffer without fail. */ 186c88b1d6cSniklas 187b305b0f1Sespie extern char *xstrdup PARAMS ((const char *)) ATTRIBUTE_MALLOC; 188b305b0f1Sespie 189b305b0f1Sespie /* Copy an existing memory buffer to a new memory buffer without fail. */ 190b305b0f1Sespie 191b305b0f1Sespie extern PTR xmemdup PARAMS ((const PTR, size_t, size_t)) ATTRIBUTE_MALLOC; 192c88b1d6cSniklas 1932159047fSniklas /* hex character manipulation routines */ 1942159047fSniklas 1952159047fSniklas #define _hex_array_size 256 1962159047fSniklas #define _hex_bad 99 1972159047fSniklas extern char _hex_value[_hex_array_size]; 1982159047fSniklas extern void hex_init PARAMS ((void)); 1992159047fSniklas #define hex_p(c) (hex_value (c) != _hex_bad) 2002159047fSniklas /* If you change this, note well: Some code relies on side effects in 2012159047fSniklas the argument being performed exactly once. */ 2022159047fSniklas #define hex_value(c) (_hex_value[(unsigned char) (c)]) 2032159047fSniklas 204b305b0f1Sespie /* Definitions used by the pexecute routine. */ 205b305b0f1Sespie 206b305b0f1Sespie #define PEXECUTE_FIRST 1 207b305b0f1Sespie #define PEXECUTE_LAST 2 208b305b0f1Sespie #define PEXECUTE_ONE (PEXECUTE_FIRST + PEXECUTE_LAST) 209b305b0f1Sespie #define PEXECUTE_SEARCH 4 210b305b0f1Sespie #define PEXECUTE_VERBOSE 8 211b305b0f1Sespie 212b305b0f1Sespie /* Execute a program. */ 213b305b0f1Sespie 214b305b0f1Sespie extern int pexecute PARAMS ((const char *, char * const *, const char *, 215b305b0f1Sespie const char *, char **, char **, int)); 216b305b0f1Sespie 217b305b0f1Sespie /* Wait for pexecute to finish. */ 218b305b0f1Sespie 219b305b0f1Sespie extern int pwait PARAMS ((int, int *, int)); 220b305b0f1Sespie 221b305b0f1Sespie /* Like sprintf but provides a pointer to malloc'd storage, which must 222b305b0f1Sespie be freed by the caller. */ 223b305b0f1Sespie 224b305b0f1Sespie extern int asprintf PARAMS ((char **, const char *, ...)) ATTRIBUTE_PRINTF_2; 225b305b0f1Sespie 226b305b0f1Sespie /* Like vsprintf but provides a pointer to malloc'd storage, which 227b305b0f1Sespie must be freed by the caller. */ 228b305b0f1Sespie 229b305b0f1Sespie extern int vasprintf PARAMS ((char **, const char *, va_list)) 230b305b0f1Sespie ATTRIBUTE_PRINTF(2,0); 231b305b0f1Sespie 232*b55d4692Sfgsch #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) 233*b55d4692Sfgsch 234b305b0f1Sespie #ifdef __cplusplus 235b305b0f1Sespie } 236b305b0f1Sespie #endif 237b305b0f1Sespie 238b305b0f1Sespie 2392159047fSniklas #endif /* ! defined (LIBIBERTY_H) */ 240