Import stripped gcc-4.0.1 sources.
[dragonfly.git] / contrib / gcc-4.0 / include / libiberty.h
blob8078a4933e488bfb57b40109d0067aca638e815c
1 /* Function declarations for libiberty.
3 Copyright 2001, 2002, 2005 Free Software Foundation, Inc.
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.
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.
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.
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.
27 Written by Cygnus Support, 1994.
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. */
35 #ifndef LIBIBERTY_H
36 #define LIBIBERTY_H
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
42 #include "ansidecl.h"
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
51 #include <stdio.h>
53 /* If the OS supports it, ensure that the supplied stream is setup to
54 avoid any multi-threaded locking. Otherwise leave the FILE pointer
55 unchanged. If the stream is NULL do nothing. */
57 extern void unlock_stream PARAMS ((FILE *));
59 /* If the OS supports it, ensure that the standard I/O streams, stdin,
60 stdout and stderr are setup to avoid any multi-threaded locking.
61 Otherwise do nothing. */
63 extern void unlock_std_streams PARAMS ((void));
65 /* Open and return a FILE pointer. If the OS supports it, ensure that
66 the stream is setup to avoid any multi-threaded locking. Otherwise
67 return the FILE pointer unchanged. */
69 extern FILE *fopen_unlocked PARAMS ((const char *, const char *));
70 extern FILE *fdopen_unlocked PARAMS ((int, const char *));
71 extern FILE *freopen_unlocked PARAMS ((const char *, const char *, FILE *));
73 /* Build an argument vector from a string. Allocates memory using
74 malloc. Use freeargv to free the vector. */
76 extern char **buildargv PARAMS ((const char *)) ATTRIBUTE_MALLOC;
78 /* Free a vector returned by buildargv. */
80 extern void freeargv PARAMS ((char **));
82 /* Duplicate an argument vector. Allocates memory using malloc. Use
83 freeargv to free the vector. */
85 extern char **dupargv PARAMS ((char **)) ATTRIBUTE_MALLOC;
88 /* Return the last component of a path name. Note that we can't use a
89 prototype here because the parameter is declared inconsistently
90 across different systems, sometimes as "char *" and sometimes as
91 "const char *" */
93 /* HAVE_DECL_* is a three-state macro: undefined, 0 or 1. If it is
94 undefined, we haven't run the autoconf check so provide the
95 declaration without arguments. If it is 0, we checked and failed
96 to find the declaration so provide a fully prototyped one. If it
97 is 1, we found it so don't provide any declaration at all. */
98 #if !HAVE_DECL_BASENAME
99 #if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || defined (__MINGW32__) || defined (HAVE_DECL_BASENAME)
100 extern char *basename PARAMS ((const char *));
101 #else
102 extern char *basename ();
103 #endif
104 #endif
106 /* A well-defined basename () that is always compiled in. */
108 extern const char *lbasename PARAMS ((const char *));
110 /* A well-defined realpath () that is always compiled in. */
112 extern char *lrealpath PARAMS ((const char *));
114 /* Concatenate an arbitrary number of strings. You must pass NULL as
115 the last argument of this function, to terminate the list of
116 strings. Allocates memory using xmalloc. */
118 extern char *concat PARAMS ((const char *, ...)) ATTRIBUTE_MALLOC ATTRIBUTE_SENTINEL;
120 /* Concatenate an arbitrary number of strings. You must pass NULL as
121 the last argument of this function, to terminate the list of
122 strings. Allocates memory using xmalloc. The first argument is
123 not one of the strings to be concatenated, but if not NULL is a
124 pointer to be freed after the new string is created, similar to the
125 way xrealloc works. */
127 extern char *reconcat PARAMS ((char *, const char *, ...)) ATTRIBUTE_MALLOC ATTRIBUTE_SENTINEL;
129 /* Determine the length of concatenating an arbitrary number of
130 strings. You must pass NULL as the last argument of this function,
131 to terminate the list of strings. */
133 extern unsigned long concat_length PARAMS ((const char *, ...)) ATTRIBUTE_SENTINEL;
135 /* Concatenate an arbitrary number of strings into a SUPPLIED area of
136 memory. You must pass NULL as the last argument of this function,
137 to terminate the list of strings. The supplied memory is assumed
138 to be large enough. */
140 extern char *concat_copy PARAMS ((char *, const char *, ...)) ATTRIBUTE_SENTINEL;
142 /* Concatenate an arbitrary number of strings into a GLOBAL area of
143 memory. You must pass NULL as the last argument of this function,
144 to terminate the list of strings. The supplied memory is assumed
145 to be large enough. */
147 extern char *concat_copy2 PARAMS ((const char *, ...)) ATTRIBUTE_SENTINEL;
149 /* This is the global area used by concat_copy2. */
151 extern char *libiberty_concat_ptr;
153 /* Concatenate an arbitrary number of strings. You must pass NULL as
154 the last argument of this function, to terminate the list of
155 strings. Allocates memory using alloca. The arguments are
156 evaluated twice! */
157 #define ACONCAT(ACONCAT_PARAMS) \
158 (libiberty_concat_ptr = alloca (concat_length ACONCAT_PARAMS + 1), \
159 concat_copy2 ACONCAT_PARAMS)
161 /* Check whether two file descriptors refer to the same file. */
163 extern int fdmatch PARAMS ((int fd1, int fd2));
165 /* Get the working directory. The result is cached, so don't call
166 chdir() between calls to getpwd(). */
168 extern char * getpwd PARAMS ((void));
170 /* Get the amount of time the process has run, in microseconds. */
172 extern long get_run_time PARAMS ((void));
174 /* Generate a relocated path to some installation directory. Allocates
175 return value using malloc. */
177 extern char *make_relative_prefix PARAMS ((const char *, const char *,
178 const char *));
180 /* Choose a temporary directory to use for scratch files. */
182 extern char *choose_temp_base PARAMS ((void)) ATTRIBUTE_MALLOC;
184 /* Return a temporary file name or NULL if unable to create one. */
186 extern char *make_temp_file PARAMS ((const char *)) ATTRIBUTE_MALLOC;
188 /* Allocate memory filled with spaces. Allocates using malloc. */
190 extern const char *spaces PARAMS ((int count));
192 /* Return the maximum error number for which strerror will return a
193 string. */
195 extern int errno_max PARAMS ((void));
197 /* Return the name of an errno value (e.g., strerrno (EINVAL) returns
198 "EINVAL"). */
200 extern const char *strerrno PARAMS ((int));
202 /* Given the name of an errno value, return the value. */
204 extern int strtoerrno PARAMS ((const char *));
206 /* ANSI's strerror(), but more robust. */
208 extern char *xstrerror PARAMS ((int));
210 /* Return the maximum signal number for which strsignal will return a
211 string. */
213 extern int signo_max PARAMS ((void));
215 /* Return a signal message string for a signal number
216 (e.g., strsignal (SIGHUP) returns something like "Hangup"). */
217 /* This is commented out as it can conflict with one in system headers.
218 We still document its existence though. */
220 /*extern const char *strsignal PARAMS ((int));*/
222 /* Return the name of a signal number (e.g., strsigno (SIGHUP) returns
223 "SIGHUP"). */
225 extern const char *strsigno PARAMS ((int));
227 /* Given the name of a signal, return its number. */
229 extern int strtosigno PARAMS ((const char *));
231 /* Register a function to be run by xexit. Returns 0 on success. */
233 extern int xatexit PARAMS ((void (*fn) (void)));
235 /* Exit, calling all the functions registered with xatexit. */
237 extern void xexit PARAMS ((int status)) ATTRIBUTE_NORETURN;
239 /* Set the program name used by xmalloc. */
241 extern void xmalloc_set_program_name PARAMS ((const char *));
243 /* Report an allocation failure. */
244 extern void xmalloc_failed PARAMS ((size_t)) ATTRIBUTE_NORETURN;
246 /* Allocate memory without fail. If malloc fails, this will print a
247 message to stderr (using the name set by xmalloc_set_program_name,
248 if any) and then call xexit. */
250 extern PTR xmalloc PARAMS ((size_t)) ATTRIBUTE_MALLOC;
252 /* Reallocate memory without fail. This works like xmalloc. Note,
253 realloc type functions are not suitable for attribute malloc since
254 they may return the same address across multiple calls. */
256 extern PTR xrealloc PARAMS ((PTR, size_t));
258 /* Allocate memory without fail and set it to zero. This works like
259 xmalloc. */
261 extern PTR xcalloc PARAMS ((size_t, size_t)) ATTRIBUTE_MALLOC;
263 /* Copy a string into a memory buffer without fail. */
265 extern char *xstrdup PARAMS ((const char *)) ATTRIBUTE_MALLOC;
267 /* Copy an existing memory buffer to a new memory buffer without fail. */
269 extern PTR xmemdup PARAMS ((const PTR, size_t, size_t)) ATTRIBUTE_MALLOC;
271 /* Physical memory routines. Return values are in BYTES. */
272 extern double physmem_total PARAMS ((void));
273 extern double physmem_available PARAMS ((void));
276 /* These macros provide a K&R/C89/C++-friendly way of allocating structures
277 with nice encapsulation. The XDELETE*() macros are technically
278 superfluous, but provided here for symmetry. Using them consistently
279 makes it easier to update client code to use different allocators such
280 as new/delete and new[]/delete[]. */
282 /* Scalar allocators. */
284 #define XNEW(T) ((T *) xmalloc (sizeof (T)))
285 #define XCNEW(T) ((T *) xcalloc (1, sizeof (T)))
286 #define XDELETE(P) free ((void*) (P))
288 /* Array allocators. */
290 #define XNEWVEC(T, N) ((T *) xmalloc (sizeof (T) * (N)))
291 #define XCNEWVEC(T, N) ((T *) xcalloc ((N), sizeof (T)))
292 #define XRESIZEVEC(T, P, N) ((T *) xrealloc ((void *) (P), sizeof (T) * (N)))
293 #define XDELETEVEC(P) free ((void*) (P))
295 /* Allocators for variable-sized structures and raw buffers. */
297 #define XNEWVAR(T, S) ((T *) xmalloc ((S)))
298 #define XCNEWVAR(T, S) ((T *) xcalloc (1, (S)))
299 #define XRESIZEVAR(T, P, S) ((T *) xrealloc ((P), (S)))
301 /* Type-safe obstack allocator. */
303 #define XOBNEW(O, T) ((T *) obstack_alloc ((O), sizeof (T)))
306 /* hex character manipulation routines */
308 #define _hex_array_size 256
309 #define _hex_bad 99
310 extern const unsigned char _hex_value[_hex_array_size];
311 extern void hex_init PARAMS ((void));
312 #define hex_p(c) (hex_value (c) != _hex_bad)
313 /* If you change this, note well: Some code relies on side effects in
314 the argument being performed exactly once. */
315 #define hex_value(c) ((unsigned int) _hex_value[(unsigned char) (c)])
317 /* Definitions used by the pexecute routine. */
319 #define PEXECUTE_FIRST 1
320 #define PEXECUTE_LAST 2
321 #define PEXECUTE_ONE (PEXECUTE_FIRST + PEXECUTE_LAST)
322 #define PEXECUTE_SEARCH 4
323 #define PEXECUTE_VERBOSE 8
325 /* Execute a program. */
327 extern int pexecute PARAMS ((const char *, char * const *, const char *,
328 const char *, char **, char **, int));
330 /* Wait for pexecute to finish. */
332 extern int pwait PARAMS ((int, int *, int));
334 #if !HAVE_DECL_ASPRINTF
335 /* Like sprintf but provides a pointer to malloc'd storage, which must
336 be freed by the caller. */
338 extern int asprintf PARAMS ((char **, const char *, ...)) ATTRIBUTE_PRINTF_2;
339 #endif
341 #if !HAVE_DECL_VASPRINTF
342 /* Like vsprintf but provides a pointer to malloc'd storage, which
343 must be freed by the caller. */
345 extern int vasprintf PARAMS ((char **, const char *, va_list))
346 ATTRIBUTE_PRINTF(2,0);
347 #endif
349 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
351 /* Drastically simplified alloca configurator. If we're using GCC,
352 we use __builtin_alloca; otherwise we use the C alloca. The C
353 alloca is always available. You can override GCC by defining
354 USE_C_ALLOCA yourself. The canonical autoconf macro C_ALLOCA is
355 also set/unset as it is often used to indicate whether code needs
356 to call alloca(0). */
357 extern PTR C_alloca PARAMS ((size_t)) ATTRIBUTE_MALLOC;
358 #undef alloca
359 #if GCC_VERSION >= 2000 && !defined USE_C_ALLOCA
360 # define alloca(x) __builtin_alloca(x)
361 # undef C_ALLOCA
362 # define ASTRDUP(X) \
363 (__extension__ ({ const char *const libiberty_optr = (X); \
364 const unsigned long libiberty_len = strlen (libiberty_optr) + 1; \
365 char *const libiberty_nptr = (char *const) alloca (libiberty_len); \
366 (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len); }))
367 #else
368 # define alloca(x) C_alloca(x)
369 # undef USE_C_ALLOCA
370 # define USE_C_ALLOCA 1
371 # undef C_ALLOCA
372 # define C_ALLOCA 1
373 extern const char *libiberty_optr;
374 extern char *libiberty_nptr;
375 extern unsigned long libiberty_len;
376 # define ASTRDUP(X) \
377 (libiberty_optr = (X), \
378 libiberty_len = strlen (libiberty_optr) + 1, \
379 libiberty_nptr = (char *) alloca (libiberty_len), \
380 (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len))
381 #endif
383 #ifdef __cplusplus
385 #endif
388 #endif /* ! defined (LIBIBERTY_H) */