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