00001 /* 00002 * Copyright 2003, 2004, 2005, 2006 PathScale, Inc. All Rights Reserved. 00003 */ 00004 00005 /* Function declarations for libiberty. 00006 00007 Copyright 2001, 2002 Free Software Foundation, Inc. 00008 00009 Note - certain prototypes declared in this header file are for 00010 functions whoes implementation copyright does not belong to the 00011 FSF. Those prototypes are present in this file for reference 00012 purposes only and their presence in this file should not construed 00013 as an indication of ownership by the FSF of the implementation of 00014 those functions in any way or form whatsoever. 00015 00016 This program is free software; you can redistribute it and/or modify 00017 it under the terms of the GNU General Public License as published by 00018 the Free Software Foundation; either version 2, or (at your option) 00019 any later version. 00020 00021 This program is distributed in the hope that it will be useful, 00022 but WITHOUT ANY WARRANTY; without even the implied warranty of 00023 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00024 GNU General Public License for more details. 00025 00026 You should have received a copy of the GNU General Public License 00027 along with this program; if not, write to the Free Software 00028 Foundation, Inc., 59 Temple Place - Suite 330, 00029 Boston, MA 02111-1307, USA. 00030 00031 Written by Cygnus Support, 1994. 00032 00033 The libiberty library provides a number of functions which are 00034 missing on some operating systems. We do not declare those here, 00035 to avoid conflicts with the system header files on operating 00036 systems that do support those functions. In this file we only 00037 declare those functions which are specific to libiberty. */ 00038 00039 #ifndef LIBIBERTY_H 00040 #define LIBIBERTY_H 00041 00042 #ifdef __cplusplus 00043 extern "C" { 00044 #endif 00045 00046 #include "ansidecl.h" 00047 00048 #ifdef ANSI_PROTOTYPES 00049 /* Get a definition for size_t. */ 00050 #include <stddef.h> 00051 /* Get a definition for va_list. */ 00052 #include <stdarg.h> 00053 #endif 00054 00055 /* Build an argument vector from a string. Allocates memory using 00056 malloc. Use freeargv to free the vector. */ 00057 00058 extern char **buildargv PARAMS ((const char *)) ATTRIBUTE_MALLOC; 00059 00060 /* Free a vector returned by buildargv. */ 00061 00062 extern void freeargv PARAMS ((char **)); 00063 00064 /* Duplicate an argument vector. Allocates memory using malloc. Use 00065 freeargv to free the vector. */ 00066 00067 extern char **dupargv PARAMS ((char **)) ATTRIBUTE_MALLOC; 00068 00069 00070 /* Return the last component of a path name. Note that we can't use a 00071 prototype here because the parameter is declared inconsistently 00072 across different systems, sometimes as "char *" and sometimes as 00073 "const char *" */ 00074 00075 /* HAVE_DECL_* is a three-state macro: undefined, 0 or 1. If it is 00076 undefined, we haven't run the autoconf check so provide the 00077 declaration without arguments. If it is 0, we checked and failed 00078 to find the declaration so provide a fully prototyped one. If it 00079 is 1, we found it so don't provide any declaration at all. */ 00080 #if !HAVE_DECL_BASENAME 00081 #if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || defined (__MINGW32__) || defined (HAVE_DECL_BASENAME) 00082 extern char *basename PARAMS ((const char *)); 00083 #else 00084 extern char *basename (); 00085 #endif 00086 #endif 00087 00088 /* A well-defined basename () that is always compiled in. */ 00089 00090 extern const char *lbasename PARAMS ((const char *)); 00091 00092 /* A well-defined realpath () that is always compiled in. */ 00093 00094 extern char *lrealpath PARAMS ((const char *)); 00095 00096 /* Concatenate an arbitrary number of strings. You must pass NULL as 00097 the last argument of this function, to terminate the list of 00098 strings. Allocates memory using xmalloc. */ 00099 00100 extern char *concat PARAMS ((const char *, ...)) ATTRIBUTE_MALLOC ATTRIBUTE_SENTINEL; 00101 00102 /* Concatenate an arbitrary number of strings. You must pass NULL as 00103 the last argument of this function, to terminate the list of 00104 strings. Allocates memory using xmalloc. The first argument is 00105 not one of the strings to be concatenated, but if not NULL is a 00106 pointer to be freed after the new string is created, similar to the 00107 way xrealloc works. */ 00108 00109 extern char *reconcat PARAMS ((char *, const char *, ...)) ATTRIBUTE_MALLOC ATTRIBUTE_SENTINEL; 00110 00111 /* Determine the length of concatenating an arbitrary number of 00112 strings. You must pass NULL as the last argument of this function, 00113 to terminate the list of strings. */ 00114 00115 extern unsigned long concat_length PARAMS ((const char *, ...)) ATTRIBUTE_SENTINEL; 00116 00117 /* Concatenate an arbitrary number of strings into a SUPPLIED area of 00118 memory. You must pass NULL as the last argument of this function, 00119 to terminate the list of strings. The supplied memory is assumed 00120 to be large enough. */ 00121 00122 extern char *concat_copy PARAMS ((char *, const char *, ...)) ATTRIBUTE_SENTINEL; 00123 00124 /* Concatenate an arbitrary number of strings into a GLOBAL area of 00125 memory. You must pass NULL as the last argument of this function, 00126 to terminate the list of strings. The supplied memory is assumed 00127 to be large enough. */ 00128 00129 extern char *concat_copy2 PARAMS ((const char *, ...)) ATTRIBUTE_SENTINEL; 00130 00131 /* This is the global area used by concat_copy2. */ 00132 00133 extern char *libiberty_concat_ptr; 00134 00135 /* Concatenate an arbitrary number of strings. You must pass NULL as 00136 the last argument of this function, to terminate the list of 00137 strings. Allocates memory using alloca. The arguments are 00138 evaluated twice! */ 00139 #define ACONCAT(ACONCAT_PARAMS) \ 00140 (libiberty_concat_ptr = alloca (concat_length ACONCAT_PARAMS + 1), \ 00141 concat_copy2 ACONCAT_PARAMS) 00142 00143 /* Check whether two file descriptors refer to the same file. */ 00144 00145 extern int fdmatch PARAMS ((int fd1, int fd2)); 00146 00147 /* Get the working directory. The result is cached, so don't call 00148 chdir() between calls to getpwd(). */ 00149 00150 extern char * getpwd PARAMS ((void)); 00151 00152 /* Get the amount of time the process has run, in microseconds. */ 00153 00154 extern long get_run_time PARAMS ((void)); 00155 00156 /* Generate a relocated path to some installation directory. Allocates 00157 return value using malloc. */ 00158 00159 extern char *make_relative_prefix PARAMS ((const char *, const char *, 00160 const char *)); 00161 00162 /* Choose a temporary directory to use for scratch files. */ 00163 00164 extern char *choose_temp_base PARAMS ((void)) ATTRIBUTE_MALLOC; 00165 00166 /* Return a temporary file name or NULL if unable to create one. */ 00167 00168 extern char *make_temp_file PARAMS ((const char *)) ATTRIBUTE_MALLOC; 00169 00170 /* Remove a link to a file unless it is special. */ 00171 00172 extern int unlink_if_ordinary PARAMS((const char *)); 00173 00174 /* Allocate memory filled with spaces. Allocates using malloc. */ 00175 00176 extern const char *spaces PARAMS ((int count)); 00177 00178 /* Return the maximum error number for which strerror will return a 00179 string. */ 00180 00181 extern int errno_max PARAMS ((void)); 00182 00183 /* Return the name of an errno value (e.g., strerrno (EINVAL) returns 00184 "EINVAL"). */ 00185 00186 extern const char *strerrno PARAMS ((int)); 00187 00188 /* Given the name of an errno value, return the value. */ 00189 00190 extern int strtoerrno PARAMS ((const char *)); 00191 00192 /* ANSI's strerror(), but more robust. */ 00193 00194 extern char *xstrerror PARAMS ((int)); 00195 00196 /* Return the maximum signal number for which strsignal will return a 00197 string. */ 00198 00199 extern int signo_max PARAMS ((void)); 00200 00201 /* Return a signal message string for a signal number 00202 (e.g., strsignal (SIGHUP) returns something like "Hangup"). */ 00203 /* This is commented out as it can conflict with one in system headers. 00204 We still document its existence though. */ 00205 00206 /*extern const char *strsignal PARAMS ((int));*/ 00207 00208 /* Return the name of a signal number (e.g., strsigno (SIGHUP) returns 00209 "SIGHUP"). */ 00210 00211 extern const char *strsigno PARAMS ((int)); 00212 00213 /* Given the name of a signal, return its number. */ 00214 00215 extern int strtosigno PARAMS ((const char *)); 00216 00217 /* Register a function to be run by xexit. Returns 0 on success. */ 00218 00219 extern int xatexit PARAMS ((void (*fn) (void))); 00220 00221 /* Exit, calling all the functions registered with xatexit. */ 00222 00223 extern void xexit PARAMS ((int status)) ATTRIBUTE_NORETURN; 00224 00225 /* Set the program name used by xmalloc. */ 00226 00227 extern void xmalloc_set_program_name PARAMS ((const char *)); 00228 00229 /* Report an allocation failure. */ 00230 extern void xmalloc_failed PARAMS ((size_t)) ATTRIBUTE_NORETURN; 00231 00232 /* Allocate memory without fail. If malloc fails, this will print a 00233 message to stderr (using the name set by xmalloc_set_program_name, 00234 if any) and then call xexit. */ 00235 00236 extern PTR xmalloc PARAMS ((size_t)) ATTRIBUTE_MALLOC; 00237 00238 /* Reallocate memory without fail. This works like xmalloc. Note, 00239 realloc type functions are not suitable for attribute malloc since 00240 they may return the same address across multiple calls. */ 00241 00242 extern PTR xrealloc PARAMS ((PTR, size_t)); 00243 00244 /* Allocate memory without fail and set it to zero. This works like 00245 xmalloc. */ 00246 00247 extern PTR xcalloc PARAMS ((size_t, size_t)) ATTRIBUTE_MALLOC; 00248 00249 /* Copy a string into a memory buffer without fail. */ 00250 00251 extern char *xstrdup PARAMS ((const char *)) ATTRIBUTE_MALLOC; 00252 00253 /* Copy an existing memory buffer to a new memory buffer without fail. */ 00254 00255 extern PTR xmemdup PARAMS ((const PTR, size_t, size_t)) ATTRIBUTE_MALLOC; 00256 00257 /* Physical memory routines. Return values are in BYTES. */ 00258 extern double physmem_total PARAMS ((void)); 00259 extern double physmem_available PARAMS ((void)); 00260 00261 00262 /* These macros provide a K&R/C89/C++-friendly way of allocating structures 00263 with nice encapsulation. The XDELETE*() macros are technically 00264 superfluous, but provided here for symmetry. Using them consistently 00265 makes it easier to update client code to use different allocators such 00266 as new/delete and new[]/delete[]. */ 00267 00268 /* Scalar allocators. */ 00269 00270 #define XNEW(T) ((T *) xmalloc (sizeof (T))) 00271 #define XCNEW(T) ((T *) xcalloc (1, sizeof (T))) 00272 #define XDELETE(P) free ((void*) (P)) 00273 00274 /* Array allocators. */ 00275 00276 #define XNEWVEC(T, N) ((T *) xmalloc (sizeof (T) * (N))) 00277 #define XCNEWVEC(T, N) ((T *) xcalloc ((N), sizeof (T))) 00278 #define XRESIZEVEC(T, P, N) ((T *) xrealloc ((void *) (P), sizeof (T) * (N))) 00279 #define XDELETEVEC(P) free ((void*) (P)) 00280 00281 /* Allocators for variable-sized structures and raw buffers. */ 00282 00283 #define XNEWVAR(T, S) ((T *) xmalloc ((S))) 00284 #define XCNEWVAR(T, S) ((T *) xcalloc (1, (S))) 00285 #define XRESIZEVAR(T, P, S) ((T *) xrealloc ((P), (S))) 00286 00287 /* Type-safe obstack allocator. */ 00288 00289 #define XOBNEW(O, T) ((T *) obstack_alloc ((O), sizeof (T))) 00290 00291 00292 /* hex character manipulation routines */ 00293 00294 #define _hex_array_size 256 00295 #define _hex_bad 99 00296 extern const unsigned char _hex_value[_hex_array_size]; 00297 extern void hex_init PARAMS ((void)); 00298 #define hex_p(c) (hex_value (c) != _hex_bad) 00299 /* If you change this, note well: Some code relies on side effects in 00300 the argument being performed exactly once. */ 00301 #define hex_value(c) ((unsigned int) _hex_value[(unsigned char) (c)]) 00302 00303 /* Definitions used by the pexecute routine. */ 00304 00305 #define PEXECUTE_FIRST 1 00306 #define PEXECUTE_LAST 2 00307 #define PEXECUTE_ONE (PEXECUTE_FIRST + PEXECUTE_LAST) 00308 #define PEXECUTE_SEARCH 4 00309 #define PEXECUTE_VERBOSE 8 00310 00311 /* Execute a program. */ 00312 00313 extern int pexecute PARAMS ((const char *, char * const *, const char *, 00314 const char *, char **, char **, int)); 00315 00316 /* Wait for pexecute to finish. */ 00317 00318 extern int pwait PARAMS ((int, int *, int)); 00319 00320 #if !HAVE_DECL_ASPRINTF 00321 /* Like sprintf but provides a pointer to malloc'd storage, which must 00322 be freed by the caller. */ 00323 00324 extern int asprintf PARAMS ((char **, const char *, ...)) ATTRIBUTE_PRINTF_2; 00325 #endif 00326 00327 #if !HAVE_DECL_VASPRINTF 00328 /* Like vsprintf but provides a pointer to malloc'd storage, which 00329 must be freed by the caller. */ 00330 00331 extern int vasprintf PARAMS ((char **, const char *, va_list)) 00332 ATTRIBUTE_PRINTF(2,0); 00333 #endif 00334 00335 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) 00336 00337 /* Drastically simplified alloca configurator. If we're using GCC, 00338 we use __builtin_alloca; otherwise we use the C alloca. The C 00339 alloca is always available. You can override GCC by defining 00340 USE_C_ALLOCA yourself. The canonical autoconf macro C_ALLOCA is 00341 also set/unset as it is often used to indicate whether code needs 00342 to call alloca(0). */ 00343 extern PTR C_alloca PARAMS ((size_t)) ATTRIBUTE_MALLOC; 00344 #undef alloca 00345 #if GCC_VERSION >= 2000 && !defined USE_C_ALLOCA 00346 # define alloca(x) __builtin_alloca(x) 00347 # undef C_ALLOCA 00348 # define ASTRDUP(X) \ 00349 (__extension__ ({ const char *const libiberty_optr = (X); \ 00350 const unsigned long libiberty_len = strlen (libiberty_optr) + 1; \ 00351 char *const libiberty_nptr = (char *const) alloca (libiberty_len); \ 00352 (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len); })) 00353 #else 00354 # define alloca(x) C_alloca(x) 00355 # undef USE_C_ALLOCA 00356 # define USE_C_ALLOCA 1 00357 # undef C_ALLOCA 00358 # define C_ALLOCA 1 00359 extern const char *libiberty_optr; 00360 extern char *libiberty_nptr; 00361 extern unsigned long libiberty_len; 00362 # define ASTRDUP(X) \ 00363 (libiberty_optr = (X), \ 00364 libiberty_len = strlen (libiberty_optr) + 1, \ 00365 libiberty_nptr = (char *) alloca (libiberty_len), \ 00366 (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len)) 00367 #endif 00368 00369 #ifdef __cplusplus 00370 } 00371 #endif 00372 00373 00374 #endif /* ! defined (LIBIBERTY_H) */
1.5.6