* config/h8300/clzsi2.c: Remove.
[official-gcc.git] / include / libiberty.h
blobf9916c58c7382ec58dfd76601529cad73ea621e2
1 /* Function declarations for libiberty.
3 Copyright 2001, 2002 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 /* Build an argument vector from a string. Allocates memory using
52 malloc. Use freeargv to free the vector. */
54 extern char **buildargv PARAMS ((const char *)) ATTRIBUTE_MALLOC;
56 /* Free a vector returned by buildargv. */
58 extern void freeargv PARAMS ((char **));
60 /* Duplicate an argument vector. Allocates memory using malloc. Use
61 freeargv to free the vector. */
63 extern char **dupargv PARAMS ((char **)) ATTRIBUTE_MALLOC;
66 /* Return the last component of a path name. Note that we can't use a
67 prototype here because the parameter is declared inconsistently
68 across different systems, sometimes as "char *" and sometimes as
69 "const char *" */
71 /* HAVE_DECL_* is a three-state macro: undefined, 0 or 1. If it is
72 undefined, we haven't run the autoconf check so provide the
73 declaration without arguments. If it is 0, we checked and failed
74 to find the declaration so provide a fully prototyped one. If it
75 is 1, we found it so don't provide any declaration at all. */
76 #if !HAVE_DECL_BASENAME
77 #if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || defined (HAVE_DECL_BASENAME)
78 extern char *basename PARAMS ((const char *));
79 #else
80 extern char *basename ();
81 #endif
82 #endif
84 /* A well-defined basename () that is always compiled in. */
86 extern const char *lbasename PARAMS ((const char *));
88 /* Concatenate an arbitrary number of strings. You must pass NULL as
89 the last argument of this function, to terminate the list of
90 strings. Allocates memory using xmalloc. */
92 extern char *concat PARAMS ((const char *, ...)) ATTRIBUTE_MALLOC;
94 /* Concatenate an arbitrary number of strings. You must pass NULL as
95 the last argument of this function, to terminate the list of
96 strings. Allocates memory using xmalloc. The first argument is
97 not one of the strings to be concatenated, but if not NULL is a
98 pointer to be freed after the new string is created, similar to the
99 way xrealloc works. */
101 extern char *reconcat PARAMS ((char *, const char *, ...)) ATTRIBUTE_MALLOC;
103 /* Determine the length of concatenating an arbitrary number of
104 strings. You must pass NULL as the last argument of this function,
105 to terminate the list of strings. */
107 extern unsigned long concat_length PARAMS ((const char *, ...));
109 /* Concatenate an arbitrary number of strings into a SUPPLIED area of
110 memory. You must pass NULL as the last argument of this function,
111 to terminate the list of strings. The supplied memory is assumed
112 to be large enough. */
114 extern char *concat_copy PARAMS ((char *, const char *, ...));
116 /* Concatenate an arbitrary number of strings into a GLOBAL 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. */
121 extern char *concat_copy2 PARAMS ((const char *, ...));
123 /* This is the global area used by concat_copy2. */
125 extern char *libiberty_concat_ptr;
127 /* Concatenate an arbitrary number of strings. You must pass NULL as
128 the last argument of this function, to terminate the list of
129 strings. Allocates memory using alloca. The arguments are
130 evaluated twice! */
131 #define ACONCAT(ACONCAT_PARAMS) \
132 (libiberty_concat_ptr = alloca (concat_length ACONCAT_PARAMS + 1), \
133 concat_copy2 ACONCAT_PARAMS)
135 /* Check whether two file descriptors refer to the same file. */
137 extern int fdmatch PARAMS ((int fd1, int fd2));
139 /* Get the working directory. The result is cached, so don't call
140 chdir() between calls to getpwd(). */
142 extern char * getpwd PARAMS ((void));
144 /* Get the amount of time the process has run, in microseconds. */
146 extern long get_run_time PARAMS ((void));
148 /* Generate a relocated path to some installation directory. Allocates
149 return value using malloc. */
151 extern char *make_relative_prefix PARAMS ((const char *, const char *,
152 const char *));
154 /* Choose a temporary directory to use for scratch files. */
156 extern char *choose_temp_base PARAMS ((void)) ATTRIBUTE_MALLOC;
158 /* Return a temporary file name or NULL if unable to create one. */
160 extern char *make_temp_file PARAMS ((const char *)) ATTRIBUTE_MALLOC;
162 /* Allocate memory filled with spaces. Allocates using malloc. */
164 extern const char *spaces PARAMS ((int count));
166 /* Return the maximum error number for which strerror will return a
167 string. */
169 extern int errno_max PARAMS ((void));
171 /* Return the name of an errno value (e.g., strerrno (EINVAL) returns
172 "EINVAL"). */
174 extern const char *strerrno PARAMS ((int));
176 /* Given the name of an errno value, return the value. */
178 extern int strtoerrno PARAMS ((const char *));
180 /* ANSI's strerror(), but more robust. */
182 extern char *xstrerror PARAMS ((int));
184 /* Return the maximum signal number for which strsignal will return a
185 string. */
187 extern int signo_max PARAMS ((void));
189 /* Return a signal message string for a signal number
190 (e.g., strsignal (SIGHUP) returns something like "Hangup"). */
191 /* This is commented out as it can conflict with one in system headers.
192 We still document its existence though. */
194 /*extern const char *strsignal PARAMS ((int));*/
196 /* Return the name of a signal number (e.g., strsigno (SIGHUP) returns
197 "SIGHUP"). */
199 extern const char *strsigno PARAMS ((int));
201 /* Given the name of a signal, return its number. */
203 extern int strtosigno PARAMS ((const char *));
205 /* Register a function to be run by xexit. Returns 0 on success. */
207 extern int xatexit PARAMS ((void (*fn) (void)));
209 /* Exit, calling all the functions registered with xatexit. */
211 extern void xexit PARAMS ((int status)) ATTRIBUTE_NORETURN;
213 /* Set the program name used by xmalloc. */
215 extern void xmalloc_set_program_name PARAMS ((const char *));
217 /* Report an allocation failure. */
218 extern void xmalloc_failed PARAMS ((size_t)) ATTRIBUTE_NORETURN;
220 /* Allocate memory without fail. If malloc fails, this will print a
221 message to stderr (using the name set by xmalloc_set_program_name,
222 if any) and then call xexit. */
224 extern PTR xmalloc PARAMS ((size_t)) ATTRIBUTE_MALLOC;
226 /* Reallocate memory without fail. This works like xmalloc. Note,
227 realloc type functions are not suitable for attribute malloc since
228 they may return the same address across multiple calls. */
230 extern PTR xrealloc PARAMS ((PTR, size_t));
232 /* Allocate memory without fail and set it to zero. This works like
233 xmalloc. */
235 extern PTR xcalloc PARAMS ((size_t, size_t)) ATTRIBUTE_MALLOC;
237 /* Copy a string into a memory buffer without fail. */
239 extern char *xstrdup PARAMS ((const char *)) ATTRIBUTE_MALLOC;
241 /* Copy an existing memory buffer to a new memory buffer without fail. */
243 extern PTR xmemdup PARAMS ((const PTR, size_t, size_t)) ATTRIBUTE_MALLOC;
245 /* hex character manipulation routines */
247 #define _hex_array_size 256
248 #define _hex_bad 99
249 extern const char _hex_value[_hex_array_size];
250 extern void hex_init PARAMS ((void));
251 #define hex_p(c) (hex_value (c) != _hex_bad)
252 /* If you change this, note well: Some code relies on side effects in
253 the argument being performed exactly once. */
254 #define hex_value(c) (_hex_value[(unsigned char) (c)])
256 /* Definitions used by the pexecute routine. */
258 #define PEXECUTE_FIRST 1
259 #define PEXECUTE_LAST 2
260 #define PEXECUTE_ONE (PEXECUTE_FIRST + PEXECUTE_LAST)
261 #define PEXECUTE_SEARCH 4
262 #define PEXECUTE_VERBOSE 8
264 /* Execute a program. */
266 extern int pexecute PARAMS ((const char *, char * const *, const char *,
267 const char *, char **, char **, int));
269 /* Wait for pexecute to finish. */
271 extern int pwait PARAMS ((int, int *, int));
273 #if !HAVE_DECL_ASPRINTF
274 /* Like sprintf but provides a pointer to malloc'd storage, which must
275 be freed by the caller. */
277 extern int asprintf PARAMS ((char **, const char *, ...)) ATTRIBUTE_PRINTF_2;
278 #endif
280 #if !HAVE_DECL_VASPRINTF
281 /* Like vsprintf but provides a pointer to malloc'd storage, which
282 must be freed by the caller. */
284 extern int vasprintf PARAMS ((char **, const char *, va_list))
285 ATTRIBUTE_PRINTF(2,0);
286 #endif
288 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
290 /* Drastically simplified alloca configurator. If we're using GCC,
291 we use __builtin_alloca; otherwise we use the C alloca. The C
292 alloca is always available. You can override GCC by defining
293 USE_C_ALLOCA yourself. The canonical autoconf macro C_ALLOCA is
294 also set/unset as it is often used to indicate whether code needs
295 to call alloca(0). */
296 extern PTR C_alloca PARAMS ((size_t)) ATTRIBUTE_MALLOC;
297 #undef alloca
298 #if GCC_VERSION >= 2000 && !defined USE_C_ALLOCA
299 # define alloca(x) __builtin_alloca(x)
300 # undef C_ALLOCA
301 # define ASTRDUP(X) \
302 (__extension__ ({ const char *const libiberty_optr = (X); \
303 const unsigned long libiberty_len = strlen (libiberty_optr) + 1; \
304 char *const libiberty_nptr = alloca (libiberty_len); \
305 (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len); }))
306 #else
307 # define alloca(x) C_alloca(x)
308 # undef USE_C_ALLOCA
309 # define USE_C_ALLOCA 1
310 # undef C_ALLOCA
311 # define C_ALLOCA 1
312 extern const char *libiberty_optr;
313 extern char *libiberty_nptr;
314 extern unsigned long libiberty_len;
315 # define ASTRDUP(X) \
316 (libiberty_optr = (X), \
317 libiberty_len = strlen (libiberty_optr) + 1, \
318 libiberty_nptr = alloca (libiberty_len), \
319 (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len))
320 #endif
322 #ifdef __cplusplus
324 #endif
327 #endif /* ! defined (LIBIBERTY_H) */