* archive.c: Include hashtab.h.
[deliverable/binutils-gdb.git] / include / libiberty.h
CommitLineData
252b5132 1/* Function declarations for libiberty.
4f1d9bd8 2
1d619e59 3 Copyright 2001, 2002 Free Software Foundation, Inc.
4f1d9bd8 4
526c3e12
NC
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
4f1d9bd8
NC
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
252b5132
RH
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
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42#include "ansidecl.h"
43
b13291a9
DD
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
252b5132
RH
51/* Build an argument vector from a string. Allocates memory using
52 malloc. Use freeargv to free the vector. */
53
e6450fe5 54extern char **buildargv PARAMS ((const char *)) ATTRIBUTE_MALLOC;
252b5132
RH
55
56/* Free a vector returned by buildargv. */
57
58extern void freeargv PARAMS ((char **));
59
60/* Duplicate an argument vector. Allocates memory using malloc. Use
61 freeargv to free the vector. */
62
cc89ffe6 63extern char **dupargv PARAMS ((char **)) ATTRIBUTE_MALLOC;
252b5132
RH
64
65
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
79c6de76
L
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. */
931f285f 76#if !HAVE_DECL_BASENAME
79fadcb0 77#if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || defined (__MINGW32__) || defined (HAVE_DECL_BASENAME)
252b5132
RH
78extern char *basename PARAMS ((const char *));
79#else
80extern char *basename ();
931f285f 81#endif
252b5132
RH
82#endif
83
8aa30e60
DD
84/* A well-defined basename () that is always compiled in. */
85
3ea71002 86extern const char *lbasename PARAMS ((const char *));
8aa30e60 87
e2803db9
DJ
88/* A well-defined realpath () that is always compiled in. */
89
90extern char *lrealpath PARAMS ((const char *));
91
38bfaea8
DD
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. */
252b5132 95
a5ecc6a5 96extern char *concat PARAMS ((const char *, ...)) ATTRIBUTE_MALLOC ATTRIBUTE_SENTINEL;
252b5132 97
99ee3a8f
DD
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
a5ecc6a5 105extern char *reconcat PARAMS ((char *, const char *, ...)) ATTRIBUTE_MALLOC ATTRIBUTE_SENTINEL;
99ee3a8f 106
54c20242 107/* Determine the length of concatenating an arbitrary number of
38bfaea8
DD
108 strings. You must pass NULL as the last argument of this function,
109 to terminate the list of strings. */
54c20242 110
a5ecc6a5 111extern unsigned long concat_length PARAMS ((const char *, ...)) ATTRIBUTE_SENTINEL;
54c20242
DD
112
113/* Concatenate an arbitrary number of strings into a SUPPLIED area of
38bfaea8
DD
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. */
54c20242 117
a5ecc6a5 118extern char *concat_copy PARAMS ((char *, const char *, ...)) ATTRIBUTE_SENTINEL;
54c20242
DD
119
120/* Concatenate an arbitrary number of strings into a GLOBAL area of
38bfaea8
DD
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. */
54c20242 124
a5ecc6a5 125extern char *concat_copy2 PARAMS ((const char *, ...)) ATTRIBUTE_SENTINEL;
54c20242
DD
126
127/* This is the global area used by concat_copy2. */
128
129extern char *libiberty_concat_ptr;
130
38bfaea8
DD
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! */
54c20242
DD
135#define ACONCAT(ACONCAT_PARAMS) \
136 (libiberty_concat_ptr = alloca (concat_length ACONCAT_PARAMS + 1), \
137 concat_copy2 ACONCAT_PARAMS)
138
252b5132
RH
139/* Check whether two file descriptors refer to the same file. */
140
141extern int fdmatch PARAMS ((int fd1, int fd2));
142
cc89ffe6
ILT
143/* Get the working directory. The result is cached, so don't call
144 chdir() between calls to getpwd(). */
145
146extern char * getpwd PARAMS ((void));
147
252b5132
RH
148/* Get the amount of time the process has run, in microseconds. */
149
150extern long get_run_time PARAMS ((void));
151
2a80c0a4
DD
152/* Generate a relocated path to some installation directory. Allocates
153 return value using malloc. */
154
155extern char *make_relative_prefix PARAMS ((const char *, const char *,
156 const char *));
157
252b5132
RH
158/* Choose a temporary directory to use for scratch files. */
159
cc89ffe6
ILT
160extern char *choose_temp_base PARAMS ((void)) ATTRIBUTE_MALLOC;
161
162/* Return a temporary file name or NULL if unable to create one. */
163
164extern char *make_temp_file PARAMS ((const char *)) ATTRIBUTE_MALLOC;
252b5132 165
190eb137
DD
166/* Remove a link to a file unless it is special. */
167
168extern int unlink_if_ordinary PARAMS((const char *));
169
252b5132
RH
170/* Allocate memory filled with spaces. Allocates using malloc. */
171
172extern const char *spaces PARAMS ((int count));
173
174/* Return the maximum error number for which strerror will return a
175 string. */
176
177extern int errno_max PARAMS ((void));
178
179/* Return the name of an errno value (e.g., strerrno (EINVAL) returns
180 "EINVAL"). */
181
182extern const char *strerrno PARAMS ((int));
183
184/* Given the name of an errno value, return the value. */
185
186extern int strtoerrno PARAMS ((const char *));
187
188/* ANSI's strerror(), but more robust. */
189
190extern char *xstrerror PARAMS ((int));
191
192/* Return the maximum signal number for which strsignal will return a
193 string. */
194
195extern int signo_max PARAMS ((void));
196
197/* Return a signal message string for a signal number
198 (e.g., strsignal (SIGHUP) returns something like "Hangup"). */
199/* This is commented out as it can conflict with one in system headers.
200 We still document its existence though. */
201
202/*extern const char *strsignal PARAMS ((int));*/
203
204/* Return the name of a signal number (e.g., strsigno (SIGHUP) returns
205 "SIGHUP"). */
206
207extern const char *strsigno PARAMS ((int));
208
209/* Given the name of a signal, return its number. */
210
211extern int strtosigno PARAMS ((const char *));
212
213/* Register a function to be run by xexit. Returns 0 on success. */
214
215extern int xatexit PARAMS ((void (*fn) (void)));
216
217/* Exit, calling all the functions registered with xatexit. */
218
cc89ffe6 219extern void xexit PARAMS ((int status)) ATTRIBUTE_NORETURN;
252b5132
RH
220
221/* Set the program name used by xmalloc. */
222
223extern void xmalloc_set_program_name PARAMS ((const char *));
224
b13291a9
DD
225/* Report an allocation failure. */
226extern void xmalloc_failed PARAMS ((size_t)) ATTRIBUTE_NORETURN;
227
252b5132
RH
228/* Allocate memory without fail. If malloc fails, this will print a
229 message to stderr (using the name set by xmalloc_set_program_name,
230 if any) and then call xexit. */
231
cc89ffe6 232extern PTR xmalloc PARAMS ((size_t)) ATTRIBUTE_MALLOC;
252b5132 233
cc89ffe6
ILT
234/* Reallocate memory without fail. This works like xmalloc. Note,
235 realloc type functions are not suitable for attribute malloc since
236 they may return the same address across multiple calls. */
252b5132
RH
237
238extern PTR xrealloc PARAMS ((PTR, size_t));
239
240/* Allocate memory without fail and set it to zero. This works like
241 xmalloc. */
242
cc89ffe6 243extern PTR xcalloc PARAMS ((size_t, size_t)) ATTRIBUTE_MALLOC;
252b5132
RH
244
245/* Copy a string into a memory buffer without fail. */
246
cc89ffe6
ILT
247extern char *xstrdup PARAMS ((const char *)) ATTRIBUTE_MALLOC;
248
249/* Copy an existing memory buffer to a new memory buffer without fail. */
250
251extern PTR xmemdup PARAMS ((const PTR, size_t, size_t)) ATTRIBUTE_MALLOC;
252b5132 252
638ceb1a 253/* Physical memory routines. Return values are in BYTES. */
4938384a
DD
254extern double physmem_total PARAMS ((void));
255extern double physmem_available PARAMS ((void));
256
d5b4094f
DD
257
258/* These macros provide a K&R/C89/C++-friendly way of allocating structures
259 with nice encapsulation. The XDELETE*() macros are technically
260 superfluous, but provided here for symmetry. Using them consistently
261 makes it easier to update client code to use different allocators such
262 as new/delete and new[]/delete[]. */
263
264/* Scalar allocators. */
265
266#define XNEW(T) ((T *) xmalloc (sizeof (T)))
267#define XCNEW(T) ((T *) xcalloc (1, sizeof (T)))
deaa6723 268#define XDELETE(P) free ((void*) (P))
d5b4094f
DD
269
270/* Array allocators. */
271
272#define XNEWVEC(T, N) ((T *) xmalloc (sizeof (T) * (N)))
273#define XCNEWVEC(T, N) ((T *) xcalloc ((N), sizeof (T)))
deaa6723
DD
274#define XRESIZEVEC(T, P, N) ((T *) xrealloc ((void *) (P), sizeof (T) * (N)))
275#define XDELETEVEC(P) free ((void*) (P))
d5b4094f
DD
276
277/* Allocators for variable-sized structures and raw buffers. */
278
279#define XNEWVAR(T, S) ((T *) xmalloc ((S)))
280#define XCNEWVAR(T, S) ((T *) xcalloc (1, (S)))
281#define XRESIZEVAR(T, P, S) ((T *) xrealloc ((P), (S)))
282
283/* Type-safe obstack allocator. */
284
285#define XOBNEW(O, T) ((T *) obstack_alloc ((O), sizeof (T)))
286
287
252b5132
RH
288/* hex character manipulation routines */
289
290#define _hex_array_size 256
291#define _hex_bad 99
e4f79046 292extern const unsigned char _hex_value[_hex_array_size];
252b5132
RH
293extern void hex_init PARAMS ((void));
294#define hex_p(c) (hex_value (c) != _hex_bad)
295/* If you change this, note well: Some code relies on side effects in
296 the argument being performed exactly once. */
e4f79046 297#define hex_value(c) ((unsigned int) _hex_value[(unsigned char) (c)])
252b5132
RH
298
299/* Definitions used by the pexecute routine. */
300
301#define PEXECUTE_FIRST 1
302#define PEXECUTE_LAST 2
303#define PEXECUTE_ONE (PEXECUTE_FIRST + PEXECUTE_LAST)
304#define PEXECUTE_SEARCH 4
305#define PEXECUTE_VERBOSE 8
306
307/* Execute a program. */
308
309extern int pexecute PARAMS ((const char *, char * const *, const char *,
310 const char *, char **, char **, int));
311
312/* Wait for pexecute to finish. */
313
314extern int pwait PARAMS ((int, int *, int));
315
bb7eb039 316#if !HAVE_DECL_ASPRINTF
cc89ffe6
ILT
317/* Like sprintf but provides a pointer to malloc'd storage, which must
318 be freed by the caller. */
319
320extern int asprintf PARAMS ((char **, const char *, ...)) ATTRIBUTE_PRINTF_2;
bb7eb039 321#endif
cc89ffe6 322
bb7eb039 323#if !HAVE_DECL_VASPRINTF
cc89ffe6
ILT
324/* Like vsprintf but provides a pointer to malloc'd storage, which
325 must be freed by the caller. */
326
327extern int vasprintf PARAMS ((char **, const char *, va_list))
328 ATTRIBUTE_PRINTF(2,0);
bb7eb039 329#endif
cc89ffe6 330
b18903cb
NC
331#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
332
30673bf5
DD
333/* Drastically simplified alloca configurator. If we're using GCC,
334 we use __builtin_alloca; otherwise we use the C alloca. The C
335 alloca is always available. You can override GCC by defining
129e8d96
DD
336 USE_C_ALLOCA yourself. The canonical autoconf macro C_ALLOCA is
337 also set/unset as it is often used to indicate whether code needs
338 to call alloca(0). */
1d619e59 339extern PTR C_alloca PARAMS ((size_t)) ATTRIBUTE_MALLOC;
30673bf5
DD
340#undef alloca
341#if GCC_VERSION >= 2000 && !defined USE_C_ALLOCA
342# define alloca(x) __builtin_alloca(x)
129e8d96 343# undef C_ALLOCA
54c20242
DD
344# define ASTRDUP(X) \
345 (__extension__ ({ const char *const libiberty_optr = (X); \
346 const unsigned long libiberty_len = strlen (libiberty_optr) + 1; \
7ab9a76e 347 char *const libiberty_nptr = (char *const) alloca (libiberty_len); \
54c20242 348 (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len); }))
30673bf5
DD
349#else
350# define alloca(x) C_alloca(x)
351# undef USE_C_ALLOCA
352# define USE_C_ALLOCA 1
129e8d96
DD
353# undef C_ALLOCA
354# define C_ALLOCA 1
54c20242
DD
355extern const char *libiberty_optr;
356extern char *libiberty_nptr;
357extern unsigned long libiberty_len;
358# define ASTRDUP(X) \
359 (libiberty_optr = (X), \
360 libiberty_len = strlen (libiberty_optr) + 1, \
7ab9a76e 361 libiberty_nptr = (char *) alloca (libiberty_len), \
54c20242 362 (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len))
30673bf5
DD
363#endif
364
252b5132
RH
365#ifdef __cplusplus
366}
367#endif
368
369
370#endif /* ! defined (LIBIBERTY_H) */
This page took 0.251019 seconds and 4 git commands to generate.