xref: /haiku/src/libs/stdc++/legacy/libiberty.h (revision 16d5c24e533eb14b7b8a99ee9f3ec9ba66335b1e)
1*16d5c24eSOliver Tappe /* Function declarations for libiberty.
2*16d5c24eSOliver Tappe    Written by Cygnus Support, 1994.
3*16d5c24eSOliver Tappe 
4*16d5c24eSOliver Tappe    The libiberty library provides a number of functions which are
5*16d5c24eSOliver Tappe    missing on some operating systems.  We do not declare those here,
6*16d5c24eSOliver Tappe    to avoid conflicts with the system header files on operating
7*16d5c24eSOliver Tappe    systems that do support those functions.  In this file we only
8*16d5c24eSOliver Tappe    declare those functions which are specific to libiberty.  */
9*16d5c24eSOliver Tappe 
10*16d5c24eSOliver Tappe #ifndef LIBIBERTY_H
11*16d5c24eSOliver Tappe #define LIBIBERTY_H
12*16d5c24eSOliver Tappe 
13*16d5c24eSOliver Tappe #ifdef __cplusplus
14*16d5c24eSOliver Tappe extern "C" {
15*16d5c24eSOliver Tappe #endif
16*16d5c24eSOliver Tappe 
17*16d5c24eSOliver Tappe #include "ansidecl.h"
18*16d5c24eSOliver Tappe 
19*16d5c24eSOliver Tappe /* Build an argument vector from a string.  Allocates memory using
20*16d5c24eSOliver Tappe    malloc.  Use freeargv to free the vector.  */
21*16d5c24eSOliver Tappe 
22*16d5c24eSOliver Tappe extern char **buildargv PARAMS ((char *));
23*16d5c24eSOliver Tappe 
24*16d5c24eSOliver Tappe /* Free a vector returned by buildargv.  */
25*16d5c24eSOliver Tappe 
26*16d5c24eSOliver Tappe extern void freeargv PARAMS ((char **));
27*16d5c24eSOliver Tappe 
28*16d5c24eSOliver Tappe /* Duplicate an argument vector. Allocates memory using malloc.  Use
29*16d5c24eSOliver Tappe    freeargv to free the vector.  */
30*16d5c24eSOliver Tappe 
31*16d5c24eSOliver Tappe extern char **dupargv PARAMS ((char **));
32*16d5c24eSOliver Tappe 
33*16d5c24eSOliver Tappe 
34*16d5c24eSOliver Tappe /* Return the last component of a path name.  Note that we can't use a
35*16d5c24eSOliver Tappe    prototype here because the parameter is declared inconsistently
36*16d5c24eSOliver Tappe    across different systems, sometimes as "char *" and sometimes as
37*16d5c24eSOliver Tappe    "const char *" */
38*16d5c24eSOliver Tappe 
39*16d5c24eSOliver Tappe #if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__)
40*16d5c24eSOliver Tappe extern char *basename PARAMS ((const char *));
41*16d5c24eSOliver Tappe #else
42*16d5c24eSOliver Tappe extern char *basename ();
43*16d5c24eSOliver Tappe #endif
44*16d5c24eSOliver Tappe 
45*16d5c24eSOliver Tappe /* Concatenate an arbitrary number of strings, up to (char *) NULL.
46*16d5c24eSOliver Tappe    Allocates memory using xmalloc.  */
47*16d5c24eSOliver Tappe 
48*16d5c24eSOliver Tappe extern char *concat PARAMS ((const char *, ...));
49*16d5c24eSOliver Tappe 
50*16d5c24eSOliver Tappe /* Check whether two file descriptors refer to the same file.  */
51*16d5c24eSOliver Tappe 
52*16d5c24eSOliver Tappe extern int fdmatch PARAMS ((int fd1, int fd2));
53*16d5c24eSOliver Tappe 
54*16d5c24eSOliver Tappe /* Get the amount of time the process has run, in microseconds.  */
55*16d5c24eSOliver Tappe 
56*16d5c24eSOliver Tappe extern long get_run_time PARAMS ((void));
57*16d5c24eSOliver Tappe 
58*16d5c24eSOliver Tappe /* Choose a temporary directory to use for scratch files.  */
59*16d5c24eSOliver Tappe 
60*16d5c24eSOliver Tappe extern char *choose_temp_base PARAMS ((void));
61*16d5c24eSOliver Tappe 
62*16d5c24eSOliver Tappe /* Allocate memory filled with spaces.  Allocates using malloc.  */
63*16d5c24eSOliver Tappe 
64*16d5c24eSOliver Tappe extern const char *spaces PARAMS ((int count));
65*16d5c24eSOliver Tappe 
66*16d5c24eSOliver Tappe /* Return the maximum error number for which strerror will return a
67*16d5c24eSOliver Tappe    string.  */
68*16d5c24eSOliver Tappe 
69*16d5c24eSOliver Tappe extern int errno_max PARAMS ((void));
70*16d5c24eSOliver Tappe 
71*16d5c24eSOliver Tappe /* Return the name of an errno value (e.g., strerrno (EINVAL) returns
72*16d5c24eSOliver Tappe    "EINVAL").  */
73*16d5c24eSOliver Tappe 
74*16d5c24eSOliver Tappe extern const char *strerrno PARAMS ((int));
75*16d5c24eSOliver Tappe 
76*16d5c24eSOliver Tappe /* Given the name of an errno value, return the value.  */
77*16d5c24eSOliver Tappe 
78*16d5c24eSOliver Tappe extern int strtoerrno PARAMS ((const char *));
79*16d5c24eSOliver Tappe 
80*16d5c24eSOliver Tappe /* ANSI's strerror(), but more robust.  */
81*16d5c24eSOliver Tappe 
82*16d5c24eSOliver Tappe extern char *xstrerror PARAMS ((int));
83*16d5c24eSOliver Tappe 
84*16d5c24eSOliver Tappe /* Return the maximum signal number for which strsignal will return a
85*16d5c24eSOliver Tappe    string.  */
86*16d5c24eSOliver Tappe 
87*16d5c24eSOliver Tappe extern int signo_max PARAMS ((void));
88*16d5c24eSOliver Tappe 
89*16d5c24eSOliver Tappe /* Return a signal message string for a signal number
90*16d5c24eSOliver Tappe    (e.g., strsignal (SIGHUP) returns something like "Hangup").  */
91*16d5c24eSOliver Tappe /* This is commented out as it can conflict with one in system headers.
92*16d5c24eSOliver Tappe    We still document its existence though.  */
93*16d5c24eSOliver Tappe 
94*16d5c24eSOliver Tappe /*extern const char *strsignal PARAMS ((int));*/
95*16d5c24eSOliver Tappe 
96*16d5c24eSOliver Tappe /* Return the name of a signal number (e.g., strsigno (SIGHUP) returns
97*16d5c24eSOliver Tappe    "SIGHUP").  */
98*16d5c24eSOliver Tappe 
99*16d5c24eSOliver Tappe extern const char *strsigno PARAMS ((int));
100*16d5c24eSOliver Tappe 
101*16d5c24eSOliver Tappe /* Given the name of a signal, return its number.  */
102*16d5c24eSOliver Tappe 
103*16d5c24eSOliver Tappe extern int strtosigno PARAMS ((const char *));
104*16d5c24eSOliver Tappe 
105*16d5c24eSOliver Tappe /* Register a function to be run by xexit.  Returns 0 on success.  */
106*16d5c24eSOliver Tappe 
107*16d5c24eSOliver Tappe extern int xatexit PARAMS ((void (*fn) (void)));
108*16d5c24eSOliver Tappe 
109*16d5c24eSOliver Tappe /* Exit, calling all the functions registered with xatexit.  */
110*16d5c24eSOliver Tappe 
111*16d5c24eSOliver Tappe #ifndef __GNUC__
112*16d5c24eSOliver Tappe extern void xexit PARAMS ((int status));
113*16d5c24eSOliver Tappe #else
114*16d5c24eSOliver Tappe void xexit PARAMS ((int status)) __attribute__ ((noreturn));
115*16d5c24eSOliver Tappe #endif
116*16d5c24eSOliver Tappe 
117*16d5c24eSOliver Tappe /* Set the program name used by xmalloc.  */
118*16d5c24eSOliver Tappe 
119*16d5c24eSOliver Tappe extern void xmalloc_set_program_name PARAMS ((const char *));
120*16d5c24eSOliver Tappe 
121*16d5c24eSOliver Tappe /* Allocate memory without fail.  If malloc fails, this will print a
122*16d5c24eSOliver Tappe    message to stderr (using the name set by xmalloc_set_program_name,
123*16d5c24eSOliver Tappe    if any) and then call xexit.  */
124*16d5c24eSOliver Tappe 
125*16d5c24eSOliver Tappe #ifdef ANSI_PROTOTYPES
126*16d5c24eSOliver Tappe /* Get a definition for size_t.  */
127*16d5c24eSOliver Tappe #include <stddef.h>
128*16d5c24eSOliver Tappe #endif
129*16d5c24eSOliver Tappe extern PTR xmalloc PARAMS ((size_t));
130*16d5c24eSOliver Tappe 
131*16d5c24eSOliver Tappe /* Reallocate memory without fail.  This works like xmalloc.
132*16d5c24eSOliver Tappe 
133*16d5c24eSOliver Tappe    FIXME: We do not declare the parameter types for the same reason as
134*16d5c24eSOliver Tappe    xmalloc.  */
135*16d5c24eSOliver Tappe 
136*16d5c24eSOliver Tappe extern PTR xrealloc PARAMS ((PTR, size_t));
137*16d5c24eSOliver Tappe 
138*16d5c24eSOliver Tappe /* Allocate memory without fail and set it to zero.  This works like
139*16d5c24eSOliver Tappe    xmalloc.  */
140*16d5c24eSOliver Tappe 
141*16d5c24eSOliver Tappe extern PTR xcalloc PARAMS ((size_t, size_t));
142*16d5c24eSOliver Tappe 
143*16d5c24eSOliver Tappe /* Copy a string into a memory buffer without fail.  */
144*16d5c24eSOliver Tappe 
145*16d5c24eSOliver Tappe extern char *xstrdup PARAMS ((const char *));
146*16d5c24eSOliver Tappe 
147*16d5c24eSOliver Tappe /* hex character manipulation routines */
148*16d5c24eSOliver Tappe 
149*16d5c24eSOliver Tappe #define _hex_array_size 256
150*16d5c24eSOliver Tappe #define _hex_bad	99
151*16d5c24eSOliver Tappe extern char _hex_value[_hex_array_size];
152*16d5c24eSOliver Tappe extern void hex_init PARAMS ((void));
153*16d5c24eSOliver Tappe #define hex_p(c)	(hex_value (c) != _hex_bad)
154*16d5c24eSOliver Tappe /* If you change this, note well: Some code relies on side effects in
155*16d5c24eSOliver Tappe    the argument being performed exactly once.  */
156*16d5c24eSOliver Tappe #define hex_value(c)	(_hex_value[(unsigned char) (c)])
157*16d5c24eSOliver Tappe 
158*16d5c24eSOliver Tappe /* Definitions used by the pexecute routine.  */
159*16d5c24eSOliver Tappe 
160*16d5c24eSOliver Tappe #define PEXECUTE_FIRST   1
161*16d5c24eSOliver Tappe #define PEXECUTE_LAST    2
162*16d5c24eSOliver Tappe #define PEXECUTE_ONE     (PEXECUTE_FIRST + PEXECUTE_LAST)
163*16d5c24eSOliver Tappe #define PEXECUTE_SEARCH  4
164*16d5c24eSOliver Tappe #define PEXECUTE_VERBOSE 8
165*16d5c24eSOliver Tappe 
166*16d5c24eSOliver Tappe /* Execute a program.  */
167*16d5c24eSOliver Tappe 
168*16d5c24eSOliver Tappe extern int pexecute PARAMS ((const char *, char * const *, const char *,
169*16d5c24eSOliver Tappe 			    const char *, char **, char **, int));
170*16d5c24eSOliver Tappe 
171*16d5c24eSOliver Tappe /* Wait for pexecute to finish.  */
172*16d5c24eSOliver Tappe 
173*16d5c24eSOliver Tappe extern int pwait PARAMS ((int, int *, int));
174*16d5c24eSOliver Tappe 
175*16d5c24eSOliver Tappe #ifdef __cplusplus
176*16d5c24eSOliver Tappe }
177*16d5c24eSOliver Tappe #endif
178*16d5c24eSOliver Tappe 
179*16d5c24eSOliver Tappe 
180*16d5c24eSOliver Tappe #endif /* ! defined (LIBIBERTY_H) */
181