Fix thinko
[deliverable/binutils-gdb.git] / include / libiberty.h
CommitLineData
252b5132 1/* Function declarations for libiberty.
4f1d9bd8
NC
2
3 Copyright 2001 Free Software Foundation, Inc.
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
cc89ffe6 54extern char **buildargv PARAMS ((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. */
76#if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || (defined (HAVE_DECL_BASENAME) && !HAVE_DECL_BASENAME)
252b5132
RH
77extern char *basename PARAMS ((const char *));
78#else
79c6de76 79# if !defined (HAVE_DECL_BASENAME)
252b5132 80extern char *basename ();
79c6de76 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
38bfaea8
DD
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. */
252b5132 91
cc89ffe6 92extern char *concat PARAMS ((const char *, ...)) ATTRIBUTE_MALLOC;
252b5132 93
54c20242 94/* Determine the length of concatenating an arbitrary number of
38bfaea8
DD
95 strings. You must pass NULL as the last argument of this function,
96 to terminate the list of strings. */
54c20242
DD
97
98extern unsigned long concat_length PARAMS ((const char *, ...));
99
100/* Concatenate an arbitrary number of strings into a SUPPLIED area of
38bfaea8
DD
101 memory. You must pass NULL as the last argument of this function,
102 to terminate the list of strings. The supplied memory is assumed
103 to be large enough. */
54c20242
DD
104
105extern char *concat_copy PARAMS ((char *, const char *, ...));
106
107/* Concatenate an arbitrary number of strings into a GLOBAL area of
38bfaea8
DD
108 memory. You must pass NULL as the last argument of this function,
109 to terminate the list of strings. The supplied memory is assumed
110 to be large enough. */
54c20242
DD
111
112extern char *concat_copy2 PARAMS ((const char *, ...));
113
114/* This is the global area used by concat_copy2. */
115
116extern char *libiberty_concat_ptr;
117
38bfaea8
DD
118/* Concatenate an arbitrary number of strings. You must pass NULL as
119 the last argument of this function, to terminate the list of
120 strings. Allocates memory using alloca. The arguments are
121 evaluated twice! */
54c20242
DD
122#define ACONCAT(ACONCAT_PARAMS) \
123 (libiberty_concat_ptr = alloca (concat_length ACONCAT_PARAMS + 1), \
124 concat_copy2 ACONCAT_PARAMS)
125
252b5132
RH
126/* Check whether two file descriptors refer to the same file. */
127
128extern int fdmatch PARAMS ((int fd1, int fd2));
129
cc89ffe6
ILT
130/* Get the working directory. The result is cached, so don't call
131 chdir() between calls to getpwd(). */
132
133extern char * getpwd PARAMS ((void));
134
252b5132
RH
135/* Get the amount of time the process has run, in microseconds. */
136
137extern long get_run_time PARAMS ((void));
138
139/* Choose a temporary directory to use for scratch files. */
140
cc89ffe6
ILT
141extern char *choose_temp_base PARAMS ((void)) ATTRIBUTE_MALLOC;
142
143/* Return a temporary file name or NULL if unable to create one. */
144
145extern char *make_temp_file PARAMS ((const char *)) ATTRIBUTE_MALLOC;
252b5132
RH
146
147/* Allocate memory filled with spaces. Allocates using malloc. */
148
149extern const char *spaces PARAMS ((int count));
150
151/* Return the maximum error number for which strerror will return a
152 string. */
153
154extern int errno_max PARAMS ((void));
155
156/* Return the name of an errno value (e.g., strerrno (EINVAL) returns
157 "EINVAL"). */
158
159extern const char *strerrno PARAMS ((int));
160
161/* Given the name of an errno value, return the value. */
162
163extern int strtoerrno PARAMS ((const char *));
164
165/* ANSI's strerror(), but more robust. */
166
167extern char *xstrerror PARAMS ((int));
168
169/* Return the maximum signal number for which strsignal will return a
170 string. */
171
172extern int signo_max PARAMS ((void));
173
174/* Return a signal message string for a signal number
175 (e.g., strsignal (SIGHUP) returns something like "Hangup"). */
176/* This is commented out as it can conflict with one in system headers.
177 We still document its existence though. */
178
179/*extern const char *strsignal PARAMS ((int));*/
180
181/* Return the name of a signal number (e.g., strsigno (SIGHUP) returns
182 "SIGHUP"). */
183
184extern const char *strsigno PARAMS ((int));
185
186/* Given the name of a signal, return its number. */
187
188extern int strtosigno PARAMS ((const char *));
189
190/* Register a function to be run by xexit. Returns 0 on success. */
191
192extern int xatexit PARAMS ((void (*fn) (void)));
193
194/* Exit, calling all the functions registered with xatexit. */
195
cc89ffe6 196extern void xexit PARAMS ((int status)) ATTRIBUTE_NORETURN;
252b5132
RH
197
198/* Set the program name used by xmalloc. */
199
200extern void xmalloc_set_program_name PARAMS ((const char *));
201
b13291a9
DD
202/* Report an allocation failure. */
203extern void xmalloc_failed PARAMS ((size_t)) ATTRIBUTE_NORETURN;
204
252b5132
RH
205/* Allocate memory without fail. If malloc fails, this will print a
206 message to stderr (using the name set by xmalloc_set_program_name,
207 if any) and then call xexit. */
208
cc89ffe6 209extern PTR xmalloc PARAMS ((size_t)) ATTRIBUTE_MALLOC;
252b5132 210
cc89ffe6
ILT
211/* Reallocate memory without fail. This works like xmalloc. Note,
212 realloc type functions are not suitable for attribute malloc since
213 they may return the same address across multiple calls. */
252b5132
RH
214
215extern PTR xrealloc PARAMS ((PTR, size_t));
216
217/* Allocate memory without fail and set it to zero. This works like
218 xmalloc. */
219
cc89ffe6 220extern PTR xcalloc PARAMS ((size_t, size_t)) ATTRIBUTE_MALLOC;
252b5132
RH
221
222/* Copy a string into a memory buffer without fail. */
223
cc89ffe6
ILT
224extern char *xstrdup PARAMS ((const char *)) ATTRIBUTE_MALLOC;
225
226/* Copy an existing memory buffer to a new memory buffer without fail. */
227
228extern PTR xmemdup PARAMS ((const PTR, size_t, size_t)) ATTRIBUTE_MALLOC;
252b5132
RH
229
230/* hex character manipulation routines */
231
232#define _hex_array_size 256
233#define _hex_bad 99
234extern char _hex_value[_hex_array_size];
235extern void hex_init PARAMS ((void));
236#define hex_p(c) (hex_value (c) != _hex_bad)
237/* If you change this, note well: Some code relies on side effects in
238 the argument being performed exactly once. */
239#define hex_value(c) (_hex_value[(unsigned char) (c)])
240
241/* Definitions used by the pexecute routine. */
242
243#define PEXECUTE_FIRST 1
244#define PEXECUTE_LAST 2
245#define PEXECUTE_ONE (PEXECUTE_FIRST + PEXECUTE_LAST)
246#define PEXECUTE_SEARCH 4
247#define PEXECUTE_VERBOSE 8
248
249/* Execute a program. */
250
251extern int pexecute PARAMS ((const char *, char * const *, const char *,
252 const char *, char **, char **, int));
253
254/* Wait for pexecute to finish. */
255
256extern int pwait PARAMS ((int, int *, int));
257
cc89ffe6
ILT
258/* Like sprintf but provides a pointer to malloc'd storage, which must
259 be freed by the caller. */
260
261extern int asprintf PARAMS ((char **, const char *, ...)) ATTRIBUTE_PRINTF_2;
262
263/* Like vsprintf but provides a pointer to malloc'd storage, which
264 must be freed by the caller. */
265
266extern int vasprintf PARAMS ((char **, const char *, va_list))
267 ATTRIBUTE_PRINTF(2,0);
268
b18903cb
NC
269#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
270
30673bf5
DD
271/* Drastically simplified alloca configurator. If we're using GCC,
272 we use __builtin_alloca; otherwise we use the C alloca. The C
273 alloca is always available. You can override GCC by defining
129e8d96
DD
274 USE_C_ALLOCA yourself. The canonical autoconf macro C_ALLOCA is
275 also set/unset as it is often used to indicate whether code needs
276 to call alloca(0). */
30673bf5
DD
277extern PTR C_alloca PARAMS((size_t));
278#undef alloca
279#if GCC_VERSION >= 2000 && !defined USE_C_ALLOCA
280# define alloca(x) __builtin_alloca(x)
129e8d96 281# undef C_ALLOCA
54c20242
DD
282# define ASTRDUP(X) \
283 (__extension__ ({ const char *const libiberty_optr = (X); \
284 const unsigned long libiberty_len = strlen (libiberty_optr) + 1; \
285 char *const libiberty_nptr = alloca (libiberty_len); \
286 (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len); }))
30673bf5
DD
287#else
288# define alloca(x) C_alloca(x)
289# undef USE_C_ALLOCA
290# define USE_C_ALLOCA 1
129e8d96
DD
291# undef C_ALLOCA
292# define C_ALLOCA 1
54c20242
DD
293extern const char *libiberty_optr;
294extern char *libiberty_nptr;
295extern unsigned long libiberty_len;
296# define ASTRDUP(X) \
297 (libiberty_optr = (X), \
298 libiberty_len = strlen (libiberty_optr) + 1, \
299 libiberty_nptr = alloca (libiberty_len), \
300 (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len))
30673bf5
DD
301#endif
302
252b5132
RH
303#ifdef __cplusplus
304}
305#endif
306
307
308#endif /* ! defined (LIBIBERTY_H) */
This page took 0.093559 seconds and 4 git commands to generate.