1130812Smarcel/* Function declarations for libiberty. 2130812Smarcel 3130812Smarcel Copyright 2001, 2002 Free Software Foundation, Inc. 4130812Smarcel 5130812Smarcel Note - certain prototypes declared in this header file are for 6130812Smarcel functions whoes implementation copyright does not belong to the 7130812Smarcel FSF. Those prototypes are present in this file for reference 8130812Smarcel purposes only and their presence in this file should not construed 9130812Smarcel as an indication of ownership by the FSF of the implementation of 10130812Smarcel those functions in any way or form whatsoever. 11130812Smarcel 12130812Smarcel This program is free software; you can redistribute it and/or modify 13130812Smarcel it under the terms of the GNU General Public License as published by 14130812Smarcel the Free Software Foundation; either version 2, or (at your option) 15130812Smarcel any later version. 16130812Smarcel 17130812Smarcel This program is distributed in the hope that it will be useful, 18130812Smarcel but WITHOUT ANY WARRANTY; without even the implied warranty of 19130812Smarcel MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20130812Smarcel GNU General Public License for more details. 21130812Smarcel 22130812Smarcel You should have received a copy of the GNU General Public License 23130812Smarcel along with this program; if not, write to the Free Software 24130812Smarcel Foundation, Inc., 59 Temple Place - Suite 330, 25130812Smarcel Boston, MA 02111-1307, USA. 26130812Smarcel 27130812Smarcel Written by Cygnus Support, 1994. 28130812Smarcel 29130812Smarcel The libiberty library provides a number of functions which are 30130812Smarcel missing on some operating systems. We do not declare those here, 31130812Smarcel to avoid conflicts with the system header files on operating 32130812Smarcel systems that do support those functions. In this file we only 33130812Smarcel declare those functions which are specific to libiberty. */ 34130812Smarcel 35130812Smarcel#ifndef LIBIBERTY_H 36130812Smarcel#define LIBIBERTY_H 37130812Smarcel 38130812Smarcel#ifdef __cplusplus 39130812Smarcelextern "C" { 40130812Smarcel#endif 41130812Smarcel 42130812Smarcel#include "ansidecl.h" 43130812Smarcel 44130812Smarcel#ifdef ANSI_PROTOTYPES 45130812Smarcel/* Get a definition for size_t. */ 46130812Smarcel#include <stddef.h> 47130812Smarcel/* Get a definition for va_list. */ 48130812Smarcel#include <stdarg.h> 49130812Smarcel#endif 50130812Smarcel 51130812Smarcel/* Build an argument vector from a string. Allocates memory using 52130812Smarcel malloc. Use freeargv to free the vector. */ 53130812Smarcel 54130812Smarcelextern char **buildargv PARAMS ((const char *)) ATTRIBUTE_MALLOC; 55130812Smarcel 56130812Smarcel/* Free a vector returned by buildargv. */ 57130812Smarcel 58130812Smarcelextern void freeargv PARAMS ((char **)); 59130812Smarcel 60130812Smarcel/* Duplicate an argument vector. Allocates memory using malloc. Use 61130812Smarcel freeargv to free the vector. */ 62130812Smarcel 63130812Smarcelextern char **dupargv PARAMS ((char **)) ATTRIBUTE_MALLOC; 64130812Smarcel 65130812Smarcel 66130812Smarcel/* Return the last component of a path name. Note that we can't use a 67130812Smarcel prototype here because the parameter is declared inconsistently 68130812Smarcel across different systems, sometimes as "char *" and sometimes as 69130812Smarcel "const char *" */ 70130812Smarcel 71130812Smarcel/* HAVE_DECL_* is a three-state macro: undefined, 0 or 1. If it is 72130812Smarcel undefined, we haven't run the autoconf check so provide the 73130812Smarcel declaration without arguments. If it is 0, we checked and failed 74130812Smarcel to find the declaration so provide a fully prototyped one. If it 75130812Smarcel is 1, we found it so don't provide any declaration at all. */ 76130812Smarcel#if !HAVE_DECL_BASENAME 77130812Smarcel#if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || defined (HAVE_DECL_BASENAME) 78130812Smarcelextern char *basename PARAMS ((const char *)); 79130812Smarcel#else 80130812Smarcelextern char *basename (); 81130812Smarcel#endif 82130812Smarcel#endif 83130812Smarcel 84130812Smarcel/* A well-defined basename () that is always compiled in. */ 85130812Smarcel 86130812Smarcelextern const char *lbasename PARAMS ((const char *)); 87130812Smarcel 88130812Smarcel/* A well-defined realpath () that is always compiled in. */ 89130812Smarcel 90130812Smarcelextern char *lrealpath PARAMS ((const char *)); 91130812Smarcel 92130812Smarcel/* Concatenate an arbitrary number of strings. You must pass NULL as 93130812Smarcel the last argument of this function, to terminate the list of 94130812Smarcel strings. Allocates memory using xmalloc. */ 95130812Smarcel 96130812Smarcelextern char *concat PARAMS ((const char *, ...)) ATTRIBUTE_MALLOC; 97130812Smarcel 98130812Smarcel/* Concatenate an arbitrary number of strings. You must pass NULL as 99130812Smarcel the last argument of this function, to terminate the list of 100130812Smarcel strings. Allocates memory using xmalloc. The first argument is 101130812Smarcel not one of the strings to be concatenated, but if not NULL is a 102130812Smarcel pointer to be freed after the new string is created, similar to the 103130812Smarcel way xrealloc works. */ 104130812Smarcel 105130812Smarcelextern char *reconcat PARAMS ((char *, const char *, ...)) ATTRIBUTE_MALLOC; 106130812Smarcel 107130812Smarcel/* Determine the length of concatenating an arbitrary number of 108130812Smarcel strings. You must pass NULL as the last argument of this function, 109130812Smarcel to terminate the list of strings. */ 110130812Smarcel 111130812Smarcelextern unsigned long concat_length PARAMS ((const char *, ...)); 112130812Smarcel 113130812Smarcel/* Concatenate an arbitrary number of strings into a SUPPLIED area of 114130812Smarcel memory. You must pass NULL as the last argument of this function, 115130812Smarcel to terminate the list of strings. The supplied memory is assumed 116130812Smarcel to be large enough. */ 117130812Smarcel 118130812Smarcelextern char *concat_copy PARAMS ((char *, const char *, ...)); 119130812Smarcel 120130812Smarcel/* Concatenate an arbitrary number of strings into a GLOBAL area of 121130812Smarcel memory. You must pass NULL as the last argument of this function, 122130812Smarcel to terminate the list of strings. The supplied memory is assumed 123130812Smarcel to be large enough. */ 124130812Smarcel 125130812Smarcelextern char *concat_copy2 PARAMS ((const char *, ...)); 126130812Smarcel 127130812Smarcel/* This is the global area used by concat_copy2. */ 128130812Smarcel 129130812Smarcelextern char *libiberty_concat_ptr; 130130812Smarcel 131130812Smarcel/* Concatenate an arbitrary number of strings. You must pass NULL as 132130812Smarcel the last argument of this function, to terminate the list of 133130812Smarcel strings. Allocates memory using alloca. The arguments are 134130812Smarcel evaluated twice! */ 135130812Smarcel#define ACONCAT(ACONCAT_PARAMS) \ 136130812Smarcel (libiberty_concat_ptr = alloca (concat_length ACONCAT_PARAMS + 1), \ 137130812Smarcel concat_copy2 ACONCAT_PARAMS) 138130812Smarcel 139130812Smarcel/* Check whether two file descriptors refer to the same file. */ 140130812Smarcel 141130812Smarcelextern int fdmatch PARAMS ((int fd1, int fd2)); 142130812Smarcel 143130812Smarcel/* Get the working directory. The result is cached, so don't call 144130812Smarcel chdir() between calls to getpwd(). */ 145130812Smarcel 146130812Smarcelextern char * getpwd PARAMS ((void)); 147130812Smarcel 148130812Smarcel/* Get the amount of time the process has run, in microseconds. */ 149130812Smarcel 150130812Smarcelextern long get_run_time PARAMS ((void)); 151130812Smarcel 152130812Smarcel/* Generate a relocated path to some installation directory. Allocates 153130812Smarcel return value using malloc. */ 154130812Smarcel 155130812Smarcelextern char *make_relative_prefix PARAMS ((const char *, const char *, 156130812Smarcel const char *)); 157130812Smarcel 158130812Smarcel/* Choose a temporary directory to use for scratch files. */ 159130812Smarcel 160130812Smarcelextern char *choose_temp_base PARAMS ((void)) ATTRIBUTE_MALLOC; 161130812Smarcel 162130812Smarcel/* Return a temporary file name or NULL if unable to create one. */ 163130812Smarcel 164130812Smarcelextern char *make_temp_file PARAMS ((const char *)) ATTRIBUTE_MALLOC; 165130812Smarcel 166130812Smarcel/* Allocate memory filled with spaces. Allocates using malloc. */ 167130812Smarcel 168130812Smarcelextern const char *spaces PARAMS ((int count)); 169130812Smarcel 170130812Smarcel/* Return the maximum error number for which strerror will return a 171130812Smarcel string. */ 172130812Smarcel 173130812Smarcelextern int errno_max PARAMS ((void)); 174130812Smarcel 175130812Smarcel/* Return the name of an errno value (e.g., strerrno (EINVAL) returns 176130812Smarcel "EINVAL"). */ 177130812Smarcel 178130812Smarcelextern const char *strerrno PARAMS ((int)); 179130812Smarcel 180130812Smarcel/* Given the name of an errno value, return the value. */ 181130812Smarcel 182130812Smarcelextern int strtoerrno PARAMS ((const char *)); 183130812Smarcel 184130812Smarcel/* ANSI's strerror(), but more robust. */ 185130812Smarcel 186130812Smarcelextern char *xstrerror PARAMS ((int)); 187130812Smarcel 188130812Smarcel/* Return the maximum signal number for which strsignal will return a 189130812Smarcel string. */ 190130812Smarcel 191130812Smarcelextern int signo_max PARAMS ((void)); 192130812Smarcel 193130812Smarcel/* Return a signal message string for a signal number 194130812Smarcel (e.g., strsignal (SIGHUP) returns something like "Hangup"). */ 195130812Smarcel/* This is commented out as it can conflict with one in system headers. 196130812Smarcel We still document its existence though. */ 197130812Smarcel 198130812Smarcel/*extern const char *strsignal PARAMS ((int));*/ 199130812Smarcel 200130812Smarcel/* Return the name of a signal number (e.g., strsigno (SIGHUP) returns 201130812Smarcel "SIGHUP"). */ 202130812Smarcel 203130812Smarcelextern const char *strsigno PARAMS ((int)); 204130812Smarcel 205130812Smarcel/* Given the name of a signal, return its number. */ 206130812Smarcel 207130812Smarcelextern int strtosigno PARAMS ((const char *)); 208130812Smarcel 209130812Smarcel/* Register a function to be run by xexit. Returns 0 on success. */ 210130812Smarcel 211130812Smarcelextern int xatexit PARAMS ((void (*fn) (void))); 212130812Smarcel 213130812Smarcel/* Exit, calling all the functions registered with xatexit. */ 214130812Smarcel 215130812Smarcelextern void xexit PARAMS ((int status)) ATTRIBUTE_NORETURN; 216130812Smarcel 217130812Smarcel/* Set the program name used by xmalloc. */ 218130812Smarcel 219130812Smarcelextern void xmalloc_set_program_name PARAMS ((const char *)); 220130812Smarcel 221130812Smarcel/* Report an allocation failure. */ 222130812Smarcelextern void xmalloc_failed PARAMS ((size_t)) ATTRIBUTE_NORETURN; 223130812Smarcel 224130812Smarcel/* Allocate memory without fail. If malloc fails, this will print a 225130812Smarcel message to stderr (using the name set by xmalloc_set_program_name, 226130812Smarcel if any) and then call xexit. */ 227130812Smarcel 228130812Smarcelextern PTR xmalloc PARAMS ((size_t)) ATTRIBUTE_MALLOC; 229130812Smarcel 230130812Smarcel/* Reallocate memory without fail. This works like xmalloc. Note, 231130812Smarcel realloc type functions are not suitable for attribute malloc since 232130812Smarcel they may return the same address across multiple calls. */ 233130812Smarcel 234130812Smarcelextern PTR xrealloc PARAMS ((PTR, size_t)); 235130812Smarcel 236130812Smarcel/* Allocate memory without fail and set it to zero. This works like 237130812Smarcel xmalloc. */ 238130812Smarcel 239130812Smarcelextern PTR xcalloc PARAMS ((size_t, size_t)) ATTRIBUTE_MALLOC; 240130812Smarcel 241130812Smarcel/* Copy a string into a memory buffer without fail. */ 242130812Smarcel 243130812Smarcelextern char *xstrdup PARAMS ((const char *)) ATTRIBUTE_MALLOC; 244130812Smarcel 245130812Smarcel/* Copy an existing memory buffer to a new memory buffer without fail. */ 246130812Smarcel 247130812Smarcelextern PTR xmemdup PARAMS ((const PTR, size_t, size_t)) ATTRIBUTE_MALLOC; 248130812Smarcel 249130812Smarcel/* Physical memory routines. Return values are in BYTES. */ 250130812Smarcelextern double physmem_total PARAMS ((void)); 251130812Smarcelextern double physmem_available PARAMS ((void)); 252130812Smarcel 253130812Smarcel/* hex character manipulation routines */ 254130812Smarcel 255130812Smarcel#define _hex_array_size 256 256130812Smarcel#define _hex_bad 99 257130812Smarcelextern const unsigned char _hex_value[_hex_array_size]; 258130812Smarcelextern void hex_init PARAMS ((void)); 259130812Smarcel#define hex_p(c) (hex_value (c) != _hex_bad) 260130812Smarcel/* If you change this, note well: Some code relies on side effects in 261130812Smarcel the argument being performed exactly once. */ 262130812Smarcel#define hex_value(c) ((unsigned int) _hex_value[(unsigned char) (c)]) 263130812Smarcel 264130812Smarcel/* Definitions used by the pexecute routine. */ 265130812Smarcel 266130812Smarcel#define PEXECUTE_FIRST 1 267130812Smarcel#define PEXECUTE_LAST 2 268130812Smarcel#define PEXECUTE_ONE (PEXECUTE_FIRST + PEXECUTE_LAST) 269130812Smarcel#define PEXECUTE_SEARCH 4 270130812Smarcel#define PEXECUTE_VERBOSE 8 271130812Smarcel 272130812Smarcel/* Execute a program. */ 273130812Smarcel 274130812Smarcelextern int pexecute PARAMS ((const char *, char * const *, const char *, 275130812Smarcel const char *, char **, char **, int)); 276130812Smarcel 277130812Smarcel/* Wait for pexecute to finish. */ 278130812Smarcel 279130812Smarcelextern int pwait PARAMS ((int, int *, int)); 280130812Smarcel 281130812Smarcel#if !HAVE_DECL_ASPRINTF 282130812Smarcel/* Like sprintf but provides a pointer to malloc'd storage, which must 283130812Smarcel be freed by the caller. */ 284130812Smarcel 285130812Smarcelextern int asprintf PARAMS ((char **, const char *, ...)) ATTRIBUTE_PRINTF_2; 286130812Smarcel#endif 287130812Smarcel 288130812Smarcel#if !HAVE_DECL_VASPRINTF 289130812Smarcel/* Like vsprintf but provides a pointer to malloc'd storage, which 290130812Smarcel must be freed by the caller. */ 291130812Smarcel 292130812Smarcelextern int vasprintf PARAMS ((char **, const char *, va_list)) 293130812Smarcel ATTRIBUTE_PRINTF(2,0); 294130812Smarcel#endif 295130812Smarcel 296130812Smarcel#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) 297130812Smarcel 298130812Smarcel/* Drastically simplified alloca configurator. If we're using GCC, 299130812Smarcel we use __builtin_alloca; otherwise we use the C alloca. The C 300130812Smarcel alloca is always available. You can override GCC by defining 301130812Smarcel USE_C_ALLOCA yourself. The canonical autoconf macro C_ALLOCA is 302130812Smarcel also set/unset as it is often used to indicate whether code needs 303130812Smarcel to call alloca(0). */ 304130812Smarcelextern PTR C_alloca PARAMS ((size_t)) ATTRIBUTE_MALLOC; 305130812Smarcel#undef alloca 306130812Smarcel#if GCC_VERSION >= 2000 && !defined USE_C_ALLOCA 307130812Smarcel# define alloca(x) __builtin_alloca(x) 308130812Smarcel# undef C_ALLOCA 309130812Smarcel# define ASTRDUP(X) \ 310130812Smarcel (__extension__ ({ const char *const libiberty_optr = (X); \ 311130812Smarcel const unsigned long libiberty_len = strlen (libiberty_optr) + 1; \ 312130812Smarcel char *const libiberty_nptr = alloca (libiberty_len); \ 313130812Smarcel (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len); })) 314130812Smarcel#else 315130812Smarcel# define alloca(x) C_alloca(x) 316130812Smarcel# undef USE_C_ALLOCA 317130812Smarcel# define USE_C_ALLOCA 1 318130812Smarcel# undef C_ALLOCA 319130812Smarcel# define C_ALLOCA 1 320130812Smarcelextern const char *libiberty_optr; 321130812Smarcelextern char *libiberty_nptr; 322130812Smarcelextern unsigned long libiberty_len; 323130812Smarcel# define ASTRDUP(X) \ 324130812Smarcel (libiberty_optr = (X), \ 325130812Smarcel libiberty_len = strlen (libiberty_optr) + 1, \ 326130812Smarcel libiberty_nptr = alloca (libiberty_len), \ 327130812Smarcel (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len)) 328130812Smarcel#endif 329130812Smarcel 330130812Smarcel#ifdef __cplusplus 331130812Smarcel} 332130812Smarcel#endif 333130812Smarcel 334130812Smarcel 335130812Smarcel#endif /* ! defined (LIBIBERTY_H) */ 336