]>
Commit | Line | Data |
---|---|---|
6599da04 | 1 | /* Function declarations for libiberty. |
01f537ab NC |
2 | |
3 | Copyright 2001 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 | ||
6599da04 JM |
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 | ||
5a4917e5 JL |
38 | #ifdef __cplusplus |
39 | extern "C" { | |
40 | #endif | |
41 | ||
6599da04 JM |
42 | #include "ansidecl.h" |
43 | ||
d1209685 ZW |
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 | ||
6599da04 JM |
51 | /* Build an argument vector from a string. Allocates memory using |
52 | malloc. Use freeargv to free the vector. */ | |
53 | ||
d9465687 | 54 | extern char **buildargv PARAMS ((char *)) ATTRIBUTE_MALLOC; |
6599da04 JM |
55 | |
56 | /* Free a vector returned by buildargv. */ | |
57 | ||
58 | extern void freeargv PARAMS ((char **)); | |
59 | ||
5a4917e5 JL |
60 | /* Duplicate an argument vector. Allocates memory using malloc. Use |
61 | freeargv to free the vector. */ | |
62 | ||
d9465687 | 63 | extern char **dupargv PARAMS ((char **)) ATTRIBUTE_MALLOC; |
5a4917e5 JL |
64 | |
65 | ||
6599da04 JM |
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 *" */ | |
70 | ||
f31e826b KG |
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 defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || (defined (HAVE_DECL_BASENAME) && !HAVE_DECL_BASENAME) | |
6599da04 JM |
77 | extern char *basename PARAMS ((const char *)); |
78 | #else | |
f31e826b | 79 | # if !defined (HAVE_DECL_BASENAME) |
6599da04 | 80 | extern char *basename (); |
f31e826b | 81 | # endif |
6599da04 JM |
82 | #endif |
83 | ||
2b757d51 NB |
84 | /* A well-defined basename () that is always compiled in. */ |
85 | ||
0ef5547d | 86 | extern const char *lbasename PARAMS ((const char *)); |
2b757d51 | 87 | |
6599da04 JM |
88 | /* Concatenate an arbitrary number of strings, up to (char *) NULL. |
89 | Allocates memory using xmalloc. */ | |
90 | ||
d9465687 | 91 | extern char *concat PARAMS ((const char *, ...)) ATTRIBUTE_MALLOC; |
6599da04 JM |
92 | |
93 | /* Check whether two file descriptors refer to the same file. */ | |
94 | ||
95 | extern int fdmatch PARAMS ((int fd1, int fd2)); | |
96 | ||
25c29e1e KG |
97 | /* Get the working directory. The result is cached, so don't call |
98 | chdir() between calls to getpwd(). */ | |
99 | ||
100 | extern char * getpwd PARAMS ((void)); | |
101 | ||
6599da04 JM |
102 | /* Get the amount of time the process has run, in microseconds. */ |
103 | ||
104 | extern long get_run_time PARAMS ((void)); | |
105 | ||
106 | /* Choose a temporary directory to use for scratch files. */ | |
107 | ||
d9465687 | 108 | extern char *choose_temp_base PARAMS ((void)) ATTRIBUTE_MALLOC; |
6599da04 | 109 | |
5a657fc3 KG |
110 | /* Return a temporary file name or NULL if unable to create one. */ |
111 | ||
d9465687 | 112 | extern char *make_temp_file PARAMS ((const char *)) ATTRIBUTE_MALLOC; |
5a657fc3 | 113 | |
6599da04 JM |
114 | /* Allocate memory filled with spaces. Allocates using malloc. */ |
115 | ||
116 | extern const char *spaces PARAMS ((int count)); | |
117 | ||
118 | /* Return the maximum error number for which strerror will return a | |
119 | string. */ | |
120 | ||
121 | extern int errno_max PARAMS ((void)); | |
122 | ||
123 | /* Return the name of an errno value (e.g., strerrno (EINVAL) returns | |
124 | "EINVAL"). */ | |
125 | ||
126 | extern const char *strerrno PARAMS ((int)); | |
127 | ||
128 | /* Given the name of an errno value, return the value. */ | |
129 | ||
130 | extern int strtoerrno PARAMS ((const char *)); | |
131 | ||
132 | /* ANSI's strerror(), but more robust. */ | |
133 | ||
134 | extern char *xstrerror PARAMS ((int)); | |
135 | ||
136 | /* Return the maximum signal number for which strsignal will return a | |
137 | string. */ | |
138 | ||
139 | extern int signo_max PARAMS ((void)); | |
140 | ||
141 | /* Return a signal message string for a signal number | |
142 | (e.g., strsignal (SIGHUP) returns something like "Hangup"). */ | |
143 | /* This is commented out as it can conflict with one in system headers. | |
144 | We still document its existence though. */ | |
145 | ||
146 | /*extern const char *strsignal PARAMS ((int));*/ | |
147 | ||
148 | /* Return the name of a signal number (e.g., strsigno (SIGHUP) returns | |
149 | "SIGHUP"). */ | |
150 | ||
151 | extern const char *strsigno PARAMS ((int)); | |
152 | ||
153 | /* Given the name of a signal, return its number. */ | |
154 | ||
155 | extern int strtosigno PARAMS ((const char *)); | |
156 | ||
157 | /* Register a function to be run by xexit. Returns 0 on success. */ | |
158 | ||
159 | extern int xatexit PARAMS ((void (*fn) (void))); | |
160 | ||
161 | /* Exit, calling all the functions registered with xatexit. */ | |
162 | ||
d9465687 | 163 | extern void xexit PARAMS ((int status)) ATTRIBUTE_NORETURN; |
6599da04 JM |
164 | |
165 | /* Set the program name used by xmalloc. */ | |
166 | ||
167 | extern void xmalloc_set_program_name PARAMS ((const char *)); | |
168 | ||
d1209685 ZW |
169 | /* Report an allocation failure. */ |
170 | extern void xmalloc_failed PARAMS ((size_t)) ATTRIBUTE_NORETURN; | |
171 | ||
6599da04 JM |
172 | /* Allocate memory without fail. If malloc fails, this will print a |
173 | message to stderr (using the name set by xmalloc_set_program_name, | |
174 | if any) and then call xexit. */ | |
175 | ||
d9465687 | 176 | extern PTR xmalloc PARAMS ((size_t)) ATTRIBUTE_MALLOC; |
6599da04 | 177 | |
d9465687 KG |
178 | /* Reallocate memory without fail. This works like xmalloc. Note, |
179 | realloc type functions are not suitable for attribute malloc since | |
180 | they may return the same address across multiple calls. */ | |
6599da04 JM |
181 | |
182 | extern PTR xrealloc PARAMS ((PTR, size_t)); | |
183 | ||
67d0f6ab KG |
184 | /* Allocate memory without fail and set it to zero. This works like |
185 | xmalloc. */ | |
186 | ||
d9465687 | 187 | extern PTR xcalloc PARAMS ((size_t, size_t)) ATTRIBUTE_MALLOC; |
67d0f6ab | 188 | |
6599da04 JM |
189 | /* Copy a string into a memory buffer without fail. */ |
190 | ||
d9465687 | 191 | extern char *xstrdup PARAMS ((const char *)) ATTRIBUTE_MALLOC; |
6599da04 | 192 | |
66599806 JG |
193 | /* Copy an existing memory buffer to a new memory buffer without fail. */ |
194 | ||
d9465687 | 195 | extern PTR xmemdup PARAMS ((const PTR, size_t, size_t)) ATTRIBUTE_MALLOC; |
66599806 | 196 | |
6599da04 JM |
197 | /* hex character manipulation routines */ |
198 | ||
199 | #define _hex_array_size 256 | |
200 | #define _hex_bad 99 | |
201 | extern char _hex_value[_hex_array_size]; | |
202 | extern void hex_init PARAMS ((void)); | |
203 | #define hex_p(c) (hex_value (c) != _hex_bad) | |
204 | /* If you change this, note well: Some code relies on side effects in | |
205 | the argument being performed exactly once. */ | |
206 | #define hex_value(c) (_hex_value[(unsigned char) (c)]) | |
207 | ||
208 | /* Definitions used by the pexecute routine. */ | |
209 | ||
210 | #define PEXECUTE_FIRST 1 | |
211 | #define PEXECUTE_LAST 2 | |
212 | #define PEXECUTE_ONE (PEXECUTE_FIRST + PEXECUTE_LAST) | |
213 | #define PEXECUTE_SEARCH 4 | |
214 | #define PEXECUTE_VERBOSE 8 | |
215 | ||
216 | /* Execute a program. */ | |
217 | ||
218 | extern int pexecute PARAMS ((const char *, char * const *, const char *, | |
219 | const char *, char **, char **, int)); | |
220 | ||
221 | /* Wait for pexecute to finish. */ | |
222 | ||
223 | extern int pwait PARAMS ((int, int *, int)); | |
224 | ||
146e60a0 KG |
225 | /* Like sprintf but provides a pointer to malloc'd storage, which must |
226 | be freed by the caller. */ | |
227 | ||
228 | extern int asprintf PARAMS ((char **, const char *, ...)) ATTRIBUTE_PRINTF_2; | |
229 | ||
230 | /* Like vsprintf but provides a pointer to malloc'd storage, which | |
231 | must be freed by the caller. */ | |
232 | ||
233 | extern int vasprintf PARAMS ((char **, const char *, va_list)) | |
234 | ATTRIBUTE_PRINTF(2,0); | |
235 | ||
672a59e0 GM |
236 | #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) |
237 | ||
b548dffb ZW |
238 | /* Drastically simplified alloca configurator. If we're using GCC, |
239 | we use __builtin_alloca; otherwise we use the C alloca. The C | |
240 | alloca is always available. You can override GCC by defining | |
cc56c744 KG |
241 | USE_C_ALLOCA yourself. The canonical autoconf macro C_ALLOCA is |
242 | also set/unset as it is often used to indicate whether code needs | |
243 | to call alloca(0). */ | |
b548dffb ZW |
244 | extern PTR C_alloca PARAMS((size_t)); |
245 | #undef alloca | |
246 | #if GCC_VERSION >= 2000 && !defined USE_C_ALLOCA | |
247 | # define alloca(x) __builtin_alloca(x) | |
cc56c744 | 248 | # undef C_ALLOCA |
c1d49704 KG |
249 | # define ASTRDUP(X) \ |
250 | (__extension__ ({ const char *const libiberty_optr = (X); \ | |
251 | const unsigned long libiberty_len = strlen (libiberty_optr) + 1; \ | |
252 | char *const libiberty_nptr = alloca (libiberty_len); \ | |
253 | (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len); })) | |
b548dffb ZW |
254 | #else |
255 | # define alloca(x) C_alloca(x) | |
256 | # undef USE_C_ALLOCA | |
257 | # define USE_C_ALLOCA 1 | |
cc56c744 KG |
258 | # undef C_ALLOCA |
259 | # define C_ALLOCA 1 | |
c1d49704 KG |
260 | extern const char *libiberty_optr; |
261 | extern char *libiberty_nptr; | |
262 | extern unsigned long libiberty_len; | |
263 | # define ASTRDUP(X) \ | |
264 | (libiberty_optr = (X), \ | |
265 | libiberty_len = strlen (libiberty_optr) + 1, \ | |
266 | libiberty_nptr = alloca (libiberty_len), \ | |
267 | (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len)) | |
b548dffb ZW |
268 | #endif |
269 | ||
5a4917e5 JL |
270 | #ifdef __cplusplus |
271 | } | |
272 | #endif | |
273 | ||
274 | ||
6599da04 | 275 | #endif /* ! defined (LIBIBERTY_H) */ |