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