1 |
/* Function declarations for libiberty. |
/* Function declarations for libiberty. |
2 |
|
|
3 |
|
Copyright 2001, 2002 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 |
|
|
27 |
Written by Cygnus Support, 1994. |
Written by Cygnus Support, 1994. |
28 |
|
|
29 |
The libiberty library provides a number of functions which are |
The libiberty library provides a number of functions which are |
41 |
|
|
42 |
#include "ansidecl.h" |
#include "ansidecl.h" |
43 |
|
|
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 |
|
|
51 |
/* Build an argument vector from a string. Allocates memory using |
/* Build an argument vector from a string. Allocates memory using |
52 |
malloc. Use freeargv to free the vector. */ |
malloc. Use freeargv to free the vector. */ |
53 |
|
|
54 |
extern char **buildargv PARAMS ((char *)); |
extern char **buildargv PARAMS ((const char *)) ATTRIBUTE_MALLOC; |
55 |
|
|
56 |
/* Free a vector returned by buildargv. */ |
/* Free a vector returned by buildargv. */ |
57 |
|
|
60 |
/* Duplicate an argument vector. Allocates memory using malloc. Use |
/* Duplicate an argument vector. Allocates memory using malloc. Use |
61 |
freeargv to free the vector. */ |
freeargv to free the vector. */ |
62 |
|
|
63 |
extern char **dupargv PARAMS ((char **)); |
extern char **dupargv PARAMS ((char **)) ATTRIBUTE_MALLOC; |
64 |
|
|
65 |
|
|
66 |
/* Return the last component of a path name. Note that we can't use a |
/* Return the last component of a path name. Note that we can't use a |
68 |
across different systems, sometimes as "char *" and sometimes as |
across different systems, sometimes as "char *" and sometimes as |
69 |
"const char *" */ |
"const char *" */ |
70 |
|
|
71 |
#if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) |
/* 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 *)); |
extern char *basename PARAMS ((const char *)); |
79 |
#else |
#else |
|
#ifndef __STDC__ |
|
80 |
extern char *basename (); |
extern char *basename (); |
81 |
#endif |
#endif |
82 |
#endif |
#endif |
83 |
|
|
84 |
/* Concatenate an arbitrary number of strings, up to (char *) NULL. |
/* A well-defined basename () that is always compiled in. */ |
85 |
Allocates memory using xmalloc. */ |
|
86 |
|
extern const char *lbasename PARAMS ((const char *)); |
87 |
|
|
88 |
|
/* A well-defined realpath () that is always compiled in. */ |
89 |
|
|
90 |
|
extern char *lrealpath PARAMS ((const char *)); |
91 |
|
|
92 |
|
/* Concatenate an arbitrary number of strings. You must pass NULL as |
93 |
|
the last argument of this function, to terminate the list of |
94 |
|
strings. Allocates memory using xmalloc. */ |
95 |
|
|
96 |
|
extern char *concat PARAMS ((const char *, ...)) ATTRIBUTE_MALLOC; |
97 |
|
|
98 |
|
/* Concatenate an arbitrary number of strings. You must pass NULL as |
99 |
|
the last argument of this function, to terminate the list of |
100 |
|
strings. Allocates memory using xmalloc. The first argument is |
101 |
|
not one of the strings to be concatenated, but if not NULL is a |
102 |
|
pointer to be freed after the new string is created, similar to the |
103 |
|
way xrealloc works. */ |
104 |
|
|
105 |
|
extern char *reconcat PARAMS ((char *, const char *, ...)) ATTRIBUTE_MALLOC; |
106 |
|
|
107 |
extern char *concat PARAMS ((const char *, ...)); |
/* Determine the length of concatenating an arbitrary number of |
108 |
|
strings. You must pass NULL as the last argument of this function, |
109 |
|
to terminate the list of strings. */ |
110 |
|
|
111 |
|
extern unsigned long concat_length PARAMS ((const char *, ...)); |
112 |
|
|
113 |
|
/* Concatenate an arbitrary number of strings into a SUPPLIED area of |
114 |
|
memory. You must pass NULL as the last argument of this function, |
115 |
|
to terminate the list of strings. The supplied memory is assumed |
116 |
|
to be large enough. */ |
117 |
|
|
118 |
|
extern char *concat_copy PARAMS ((char *, const char *, ...)); |
119 |
|
|
120 |
|
/* Concatenate an arbitrary number of strings into a GLOBAL area of |
121 |
|
memory. You must pass NULL as the last argument of this function, |
122 |
|
to terminate the list of strings. The supplied memory is assumed |
123 |
|
to be large enough. */ |
124 |
|
|
125 |
|
extern char *concat_copy2 PARAMS ((const char *, ...)); |
126 |
|
|
127 |
|
/* This is the global area used by concat_copy2. */ |
128 |
|
|
129 |
|
extern char *libiberty_concat_ptr; |
130 |
|
|
131 |
|
/* Concatenate an arbitrary number of strings. You must pass NULL as |
132 |
|
the last argument of this function, to terminate the list of |
133 |
|
strings. Allocates memory using alloca. The arguments are |
134 |
|
evaluated twice! */ |
135 |
|
#define ACONCAT(ACONCAT_PARAMS) \ |
136 |
|
(libiberty_concat_ptr = alloca (concat_length ACONCAT_PARAMS + 1), \ |
137 |
|
concat_copy2 ACONCAT_PARAMS) |
138 |
|
|
139 |
/* Check whether two file descriptors refer to the same file. */ |
/* Check whether two file descriptors refer to the same file. */ |
140 |
|
|
141 |
extern int fdmatch PARAMS ((int fd1, int fd2)); |
extern int fdmatch PARAMS ((int fd1, int fd2)); |
142 |
|
|
143 |
|
/* Get the working directory. The result is cached, so don't call |
144 |
|
chdir() between calls to getpwd(). */ |
145 |
|
|
146 |
|
extern char * getpwd PARAMS ((void)); |
147 |
|
|
148 |
/* Get the amount of time the process has run, in microseconds. */ |
/* Get the amount of time the process has run, in microseconds. */ |
149 |
|
|
150 |
extern long get_run_time PARAMS ((void)); |
extern long get_run_time PARAMS ((void)); |
151 |
|
|
152 |
|
/* Generate a relocated path to some installation directory. Allocates |
153 |
|
return value using malloc. */ |
154 |
|
|
155 |
|
extern char *make_relative_prefix PARAMS ((const char *, const char *, |
156 |
|
const char *)); |
157 |
|
|
158 |
/* Choose a temporary directory to use for scratch files. */ |
/* Choose a temporary directory to use for scratch files. */ |
159 |
|
|
160 |
extern char *choose_temp_base PARAMS ((void)); |
extern char *choose_temp_base PARAMS ((void)) ATTRIBUTE_MALLOC; |
161 |
|
|
162 |
|
/* Return a temporary file name or NULL if unable to create one. */ |
163 |
|
|
164 |
|
extern char *make_temp_file PARAMS ((const char *)) ATTRIBUTE_MALLOC; |
165 |
|
|
166 |
/* Allocate memory filled with spaces. Allocates using malloc. */ |
/* Allocate memory filled with spaces. Allocates using malloc. */ |
167 |
|
|
212 |
|
|
213 |
/* Exit, calling all the functions registered with xatexit. */ |
/* Exit, calling all the functions registered with xatexit. */ |
214 |
|
|
215 |
#ifndef __GNUC__ |
extern void xexit PARAMS ((int status)) ATTRIBUTE_NORETURN; |
|
extern void xexit PARAMS ((int status)); |
|
|
#else |
|
|
void xexit PARAMS ((int status)) __attribute__ ((noreturn)); |
|
|
#endif |
|
216 |
|
|
217 |
/* Set the program name used by xmalloc. */ |
/* Set the program name used by xmalloc. */ |
218 |
|
|
219 |
extern void xmalloc_set_program_name PARAMS ((const char *)); |
extern void xmalloc_set_program_name PARAMS ((const char *)); |
220 |
|
|
221 |
|
/* Report an allocation failure. */ |
222 |
|
extern void xmalloc_failed PARAMS ((size_t)) ATTRIBUTE_NORETURN; |
223 |
|
|
224 |
/* Allocate memory without fail. If malloc fails, this will print a |
/* Allocate memory without fail. If malloc fails, this will print a |
225 |
message to stderr (using the name set by xmalloc_set_program_name, |
message to stderr (using the name set by xmalloc_set_program_name, |
226 |
if any) and then call xexit. */ |
if any) and then call xexit. */ |
227 |
|
|
228 |
#ifdef ANSI_PROTOTYPES |
extern PTR xmalloc PARAMS ((size_t)) ATTRIBUTE_MALLOC; |
|
/* Get a definition for size_t. */ |
|
|
#include <stddef.h> |
|
|
#endif |
|
|
extern PTR xmalloc PARAMS ((size_t)); |
|
|
|
|
|
/* Reallocate memory without fail. This works like xmalloc. |
|
229 |
|
|
230 |
FIXME: We do not declare the parameter types for the same reason as |
/* Reallocate memory without fail. This works like xmalloc. Note, |
231 |
xmalloc. */ |
realloc type functions are not suitable for attribute malloc since |
232 |
|
they may return the same address across multiple calls. */ |
233 |
|
|
234 |
extern PTR xrealloc PARAMS ((PTR, size_t)); |
extern PTR xrealloc PARAMS ((PTR, size_t)); |
235 |
|
|
236 |
/* Allocate memory without fail and set it to zero. This works like |
/* Allocate memory without fail and set it to zero. This works like |
237 |
xmalloc. */ |
xmalloc. */ |
238 |
|
|
239 |
extern PTR xcalloc PARAMS ((size_t, size_t)); |
extern PTR xcalloc PARAMS ((size_t, size_t)) ATTRIBUTE_MALLOC; |
240 |
|
|
241 |
/* Copy a string into a memory buffer without fail. */ |
/* Copy a string into a memory buffer without fail. */ |
242 |
|
|
243 |
extern char *xstrdup PARAMS ((const char *)); |
extern char *xstrdup PARAMS ((const char *)) ATTRIBUTE_MALLOC; |
244 |
|
|
245 |
|
/* Copy an existing memory buffer to a new memory buffer without fail. */ |
246 |
|
|
247 |
|
extern PTR xmemdup PARAMS ((const PTR, size_t, size_t)) ATTRIBUTE_MALLOC; |
248 |
|
|
249 |
|
/* Physical memory routines. Return values are in BYTES. */ |
250 |
|
extern double physmem_total PARAMS ((void)); |
251 |
|
extern double physmem_available PARAMS ((void)); |
252 |
|
|
253 |
/* hex character manipulation routines */ |
/* hex character manipulation routines */ |
254 |
|
|
255 |
#define _hex_array_size 256 |
#define _hex_array_size 256 |
256 |
#define _hex_bad 99 |
#define _hex_bad 99 |
257 |
extern char _hex_value[_hex_array_size]; |
extern const unsigned char _hex_value[_hex_array_size]; |
258 |
extern void hex_init PARAMS ((void)); |
extern void hex_init PARAMS ((void)); |
259 |
#define hex_p(c) (hex_value (c) != _hex_bad) |
#define hex_p(c) (hex_value (c) != _hex_bad) |
260 |
/* If you change this, note well: Some code relies on side effects in |
/* If you change this, note well: Some code relies on side effects in |
261 |
the argument being performed exactly once. */ |
the argument being performed exactly once. */ |
262 |
#define hex_value(c) (_hex_value[(unsigned char) (c)]) |
#define hex_value(c) ((unsigned int) _hex_value[(unsigned char) (c)]) |
263 |
|
|
264 |
/* Definitions used by the pexecute routine. */ |
/* Definitions used by the pexecute routine. */ |
265 |
|
|
278 |
|
|
279 |
extern int pwait PARAMS ((int, int *, int)); |
extern int pwait PARAMS ((int, int *, int)); |
280 |
|
|
281 |
|
#if !HAVE_DECL_ASPRINTF |
282 |
|
/* Like sprintf but provides a pointer to malloc'd storage, which must |
283 |
|
be freed by the caller. */ |
284 |
|
|
285 |
|
extern int asprintf PARAMS ((char **, const char *, ...)) ATTRIBUTE_PRINTF_2; |
286 |
|
#endif |
287 |
|
|
288 |
|
#if !HAVE_DECL_VASPRINTF |
289 |
|
/* Like vsprintf but provides a pointer to malloc'd storage, which |
290 |
|
must be freed by the caller. */ |
291 |
|
|
292 |
|
extern int vasprintf PARAMS ((char **, const char *, va_list)) |
293 |
|
ATTRIBUTE_PRINTF(2,0); |
294 |
|
#endif |
295 |
|
|
296 |
|
#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) |
297 |
|
|
298 |
|
/* Drastically simplified alloca configurator. If we're using GCC, |
299 |
|
we use __builtin_alloca; otherwise we use the C alloca. The C |
300 |
|
alloca is always available. You can override GCC by defining |
301 |
|
USE_C_ALLOCA yourself. The canonical autoconf macro C_ALLOCA is |
302 |
|
also set/unset as it is often used to indicate whether code needs |
303 |
|
to call alloca(0). */ |
304 |
|
extern PTR C_alloca PARAMS ((size_t)) ATTRIBUTE_MALLOC; |
305 |
|
#undef alloca |
306 |
|
#if GCC_VERSION >= 2000 && !defined USE_C_ALLOCA |
307 |
|
# define alloca(x) __builtin_alloca(x) |
308 |
|
# undef C_ALLOCA |
309 |
|
# define ASTRDUP(X) \ |
310 |
|
(__extension__ ({ const char *const libiberty_optr = (X); \ |
311 |
|
const unsigned long libiberty_len = strlen (libiberty_optr) + 1; \ |
312 |
|
char *const libiberty_nptr = alloca (libiberty_len); \ |
313 |
|
(char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len); })) |
314 |
|
#else |
315 |
|
# define alloca(x) C_alloca(x) |
316 |
|
# undef USE_C_ALLOCA |
317 |
|
# define USE_C_ALLOCA 1 |
318 |
|
# undef C_ALLOCA |
319 |
|
# define C_ALLOCA 1 |
320 |
|
extern const char *libiberty_optr; |
321 |
|
extern char *libiberty_nptr; |
322 |
|
extern unsigned long libiberty_len; |
323 |
|
# define ASTRDUP(X) \ |
324 |
|
(libiberty_optr = (X), \ |
325 |
|
libiberty_len = strlen (libiberty_optr) + 1, \ |
326 |
|
libiberty_nptr = alloca (libiberty_len), \ |
327 |
|
(char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len)) |
328 |
|
#endif |
329 |
|
|
330 |
#ifdef __cplusplus |
#ifdef __cplusplus |
331 |
} |
} |
332 |
#endif |
#endif |