1 /* Function declarations for libiberty. 2 3 Copyright 2001, 2002 Free Software Foundation, Inc. 4 5 Note - certain prototypes declared in this header file are for 6 functions whoes implementation copyright does not belong to the 7 FSF. Those prototypes are present in this file for reference 8 purposes only and their presence in this file should not construed 9 as an indication of ownership by the FSF of the implementation of 10 those functions in any way or form whatsoever. 11 12 This program is free software; you can redistribute it and/or modify 13 it under the terms of the GNU General Public License as published by 14 the Free Software Foundation; either version 2, or (at your option) 15 any later version. 16 17 This program is distributed in the hope that it will be useful, 18 but WITHOUT ANY WARRANTY; without even the implied warranty of 19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 GNU General Public License for more details. 21 22 You should have received a copy of the GNU General Public License 23 along with this program; if not, write to the Free Software 24 Foundation, Inc., 59 Temple Place - Suite 330, 25 Boston, MA 02111-1307, USA. 26 27 Written by Cygnus Support, 1994. 28 29 The libiberty library provides a number of functions which are 30 missing on some operating systems. We do not declare those here, 31 to avoid conflicts with the system header files on operating 32 systems that do support those functions. In this file we only 33 declare those functions which are specific to libiberty. */ 34 35 #ifndef LIBIBERTY_H 36 #define LIBIBERTY_H 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 #include "ansidecl.h" 43 44 #ifdef ANSI_PROTOTYPES 45 /* Get a definition for size_t. */ 46 #include <stddef.h> 47 /* Get a definition for va_list. */ 48 #include <stdarg.h> 49 #endif 50 51 /* Build an argument vector from a string. Allocates memory using 52 malloc. Use freeargv to free the vector. */ 53 54 extern char **buildargv PARAMS ((const char *)) ATTRIBUTE_MALLOC; 55 56 /* Free a vector returned by buildargv. */ 57 58 extern void freeargv PARAMS ((char **)); 59 60 /* Duplicate an argument vector. Allocates memory using malloc. Use 61 freeargv to free the vector. */ 62 63 extern char **dupargv PARAMS ((char **)) ATTRIBUTE_MALLOC; 64 65 /* Expand "@file" arguments in argv. */ 66 67 extern void expandargv PARAMS ((int *, char ***)); 68 69 /* Return the last component of a path name. Note that we can't use a 70 prototype here because the parameter is declared inconsistently 71 across different systems, sometimes as "char *" and sometimes as 72 "const char *" */ 73 74 /* HAVE_DECL_* is a three-state macro: undefined, 0 or 1. If it is 75 undefined, we haven't run the autoconf check so provide the 76 declaration without arguments. If it is 0, we checked and failed 77 to find the declaration so provide a fully prototyped one. If it 78 is 1, we found it so don't provide any declaration at all. */ 79 #if !HAVE_DECL_BASENAME 80 #if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || defined (HAVE_DECL_BASENAME) 81 extern char *basename PARAMS ((const char *)); 82 #else 83 extern char *basename (); 84 #endif 85 #endif 86 87 /* A well-defined basename () that is always compiled in. */ 88 89 extern const char *lbasename PARAMS ((const char *)); 90 91 /* A well-defined realpath () that is always compiled in. */ 92 93 extern char *lrealpath PARAMS ((const char *)); 94 95 /* Concatenate an arbitrary number of strings. You must pass NULL as 96 the last argument of this function, to terminate the list of 97 strings. Allocates memory using xmalloc. */ 98 99 extern char *concat PARAMS ((const char *, ...)) ATTRIBUTE_MALLOC; 100 101 /* Concatenate an arbitrary number of strings. You must pass NULL as 102 the last argument of this function, to terminate the list of 103 strings. Allocates memory using xmalloc. The first argument is 104 not one of the strings to be concatenated, but if not NULL is a 105 pointer to be freed after the new string is created, similar to the 106 way xrealloc works. */ 107 108 extern char *reconcat PARAMS ((char *, const char *, ...)) ATTRIBUTE_MALLOC; 109 110 /* Determine the length of concatenating an arbitrary number of 111 strings. You must pass NULL as the last argument of this function, 112 to terminate the list of strings. */ 113 114 extern unsigned long concat_length PARAMS ((const char *, ...)); 115 116 /* Concatenate an arbitrary number of strings into a SUPPLIED area of 117 memory. You must pass NULL as the last argument of this function, 118 to terminate the list of strings. The supplied memory is assumed 119 to be large enough. */ 120 121 extern char *concat_copy PARAMS ((char *, const char *, ...)); 122 123 /* Concatenate an arbitrary number of strings into a GLOBAL area of 124 memory. You must pass NULL as the last argument of this function, 125 to terminate the list of strings. The supplied memory is assumed 126 to be large enough. */ 127 128 extern char *concat_copy2 PARAMS ((const char *, ...)); 129 130 /* This is the global area used by concat_copy2. */ 131 132 extern char *libiberty_concat_ptr; 133 134 /* Concatenate an arbitrary number of strings. You must pass NULL as 135 the last argument of this function, to terminate the list of 136 strings. Allocates memory using alloca. The arguments are 137 evaluated twice! */ 138 #define ACONCAT(ACONCAT_PARAMS) \ 139 (libiberty_concat_ptr = alloca (concat_length ACONCAT_PARAMS + 1), \ 140 concat_copy2 ACONCAT_PARAMS) 141 142 /* Check whether two file descriptors refer to the same file. */ 143 144 extern int fdmatch PARAMS ((int fd1, int fd2)); 145 146 /* Get the working directory. The result is cached, so don't call 147 chdir() between calls to getpwd(). */ 148 149 extern char * getpwd PARAMS ((void)); 150 151 /* Get the amount of time the process has run, in microseconds. */ 152 153 extern long get_run_time PARAMS ((void)); 154 155 /* Generate a relocated path to some installation directory. Allocates 156 return value using malloc. */ 157 158 extern char *make_relative_prefix PARAMS ((const char *, const char *, 159 const char *)); 160 161 /* Choose a temporary directory to use for scratch files. */ 162 163 extern char *choose_temp_base PARAMS ((void)) ATTRIBUTE_MALLOC; 164 165 /* Return a temporary file name or NULL if unable to create one. */ 166 167 extern char *make_temp_file PARAMS ((const char *)) ATTRIBUTE_MALLOC; 168 169 /* Allocate memory filled with spaces. Allocates using malloc. */ 170 171 extern const char *spaces PARAMS ((int count)); 172 173 /* Return the maximum error number for which strerror will return a 174 string. */ 175 176 extern int errno_max PARAMS ((void)); 177 178 /* Return the name of an errno value (e.g., strerrno (EINVAL) returns 179 "EINVAL"). */ 180 181 extern const char *strerrno PARAMS ((int)); 182 183 /* Given the name of an errno value, return the value. */ 184 185 extern int strtoerrno PARAMS ((const char *)); 186 187 /* ANSI's strerror(), but more robust. */ 188 189 extern char *xstrerror PARAMS ((int)); 190 191 /* Return the maximum signal number for which strsignal will return a 192 string. */ 193 194 extern int signo_max PARAMS ((void)); 195 196 /* Return a signal message string for a signal number 197 (e.g., strsignal (SIGHUP) returns something like "Hangup"). */ 198 /* This is commented out as it can conflict with one in system headers. 199 We still document its existence though. */ 200 201 /*extern const char *strsignal PARAMS ((int));*/ 202 203 /* Return the name of a signal number (e.g., strsigno (SIGHUP) returns 204 "SIGHUP"). */ 205 206 extern const char *strsigno PARAMS ((int)); 207 208 /* Given the name of a signal, return its number. */ 209 210 extern int strtosigno PARAMS ((const char *)); 211 212 /* Register a function to be run by xexit. Returns 0 on success. */ 213 214 extern int xatexit PARAMS ((void (*fn) (void))); 215 216 /* Exit, calling all the functions registered with xatexit. */ 217 218 extern void xexit PARAMS ((int status)) ATTRIBUTE_NORETURN; 219 220 /* Set the program name used by xmalloc. */ 221 222 extern void xmalloc_set_program_name PARAMS ((const char *)); 223 224 /* Report an allocation failure. */ 225 extern void xmalloc_failed PARAMS ((size_t)) ATTRIBUTE_NORETURN; 226 227 /* Allocate memory without fail. If malloc fails, this will print a 228 message to stderr (using the name set by xmalloc_set_program_name, 229 if any) and then call xexit. */ 230 231 extern PTR xmalloc PARAMS ((size_t)) ATTRIBUTE_MALLOC; 232 233 /* Reallocate memory without fail. This works like xmalloc. Note, 234 realloc type functions are not suitable for attribute malloc since 235 they may return the same address across multiple calls. */ 236 237 extern PTR xrealloc PARAMS ((PTR, size_t)); 238 239 /* Allocate memory without fail and set it to zero. This works like 240 xmalloc. */ 241 242 extern PTR xcalloc PARAMS ((size_t, size_t)) ATTRIBUTE_MALLOC; 243 244 /* Copy a string into a memory buffer without fail. */ 245 246 extern char *xstrdup PARAMS ((const char *)) ATTRIBUTE_MALLOC; 247 248 /* Copy an existing memory buffer to a new memory buffer without fail. */ 249 250 extern PTR xmemdup PARAMS ((const PTR, size_t, size_t)) ATTRIBUTE_MALLOC; 251 252 /* Physical memory routines. Return values are in BYTES. */ 253 extern double physmem_total PARAMS ((void)); 254 extern double physmem_available PARAMS ((void)); 255 256 /* hex character manipulation routines */ 257 258 #define _hex_array_size 256 259 #define _hex_bad 99 260 extern const unsigned char _hex_value[_hex_array_size]; 261 extern void hex_init PARAMS ((void)); 262 #define hex_p(c) (hex_value (c) != _hex_bad) 263 /* If you change this, note well: Some code relies on side effects in 264 the argument being performed exactly once. */ 265 #define hex_value(c) ((unsigned int) _hex_value[(unsigned char) (c)]) 266 267 /* Definitions used by the pexecute routine. */ 268 269 #define PEXECUTE_FIRST 1 270 #define PEXECUTE_LAST 2 271 #define PEXECUTE_ONE (PEXECUTE_FIRST + PEXECUTE_LAST) 272 #define PEXECUTE_SEARCH 4 273 #define PEXECUTE_VERBOSE 8 274 275 /* Execute a program. */ 276 277 extern int pexecute PARAMS ((const char *, char * const *, const char *, 278 const char *, char **, char **, int)); 279 280 /* Wait for pexecute to finish. */ 281 282 extern int pwait PARAMS ((int, int *, int)); 283 284 #if !HAVE_DECL_ASPRINTF 285 /* Like sprintf but provides a pointer to malloc'd storage, which must 286 be freed by the caller. */ 287 288 extern int asprintf PARAMS ((char **, const char *, ...)) ATTRIBUTE_PRINTF_2; 289 #endif 290 291 #if !HAVE_DECL_VASPRINTF 292 /* Like vsprintf but provides a pointer to malloc'd storage, which 293 must be freed by the caller. */ 294 295 extern int vasprintf PARAMS ((char **, const char *, va_list)) 296 ATTRIBUTE_PRINTF(2,0); 297 #endif 298 299 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) 300 301 /* Drastically simplified alloca configurator. If we're using GCC, 302 we use __builtin_alloca; otherwise we use the C alloca. The C 303 alloca is always available. You can override GCC by defining 304 USE_C_ALLOCA yourself. The canonical autoconf macro C_ALLOCA is 305 also set/unset as it is often used to indicate whether code needs 306 to call alloca(0). */ 307 extern PTR C_alloca PARAMS ((size_t)) ATTRIBUTE_MALLOC; 308 #undef alloca 309 #if GCC_VERSION >= 2000 && !defined USE_C_ALLOCA 310 # define alloca(x) __builtin_alloca(x) 311 # undef C_ALLOCA 312 # define ASTRDUP(X) \ 313 (__extension__ ({ const char *const libiberty_optr = (X); \ 314 const unsigned long libiberty_len = strlen (libiberty_optr) + 1; \ 315 char *const libiberty_nptr = alloca (libiberty_len); \ 316 (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len); })) 317 #else 318 # define alloca(x) C_alloca(x) 319 # undef USE_C_ALLOCA 320 # define USE_C_ALLOCA 1 321 # undef C_ALLOCA 322 # define C_ALLOCA 1 323 extern const char *libiberty_optr; 324 extern char *libiberty_nptr; 325 extern unsigned long libiberty_len; 326 # define ASTRDUP(X) \ 327 (libiberty_optr = (X), \ 328 libiberty_len = strlen (libiberty_optr) + 1, \ 329 libiberty_nptr = alloca (libiberty_len), \ 330 (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len)) 331 #endif 332 333 #ifdef __cplusplus 334 } 335 #endif 336 337 338 #endif /* ! defined (LIBIBERTY_H) */ 339