1169695Skan/* Function declarations for libiberty.
2169695Skan
3169695Skan   Copyright 2001, 2002, 2005 Free Software Foundation, Inc.
4169695Skan
5169695Skan   Note - certain prototypes declared in this header file are for
6169695Skan   functions whoes implementation copyright does not belong to the
7169695Skan   FSF.  Those prototypes are present in this file for reference
8169695Skan   purposes only and their presence in this file should not construed
9169695Skan   as an indication of ownership by the FSF of the implementation of
10169695Skan   those functions in any way or form whatsoever.
11169695Skan
12169695Skan   This program is free software; you can redistribute it and/or modify
13169695Skan   it under the terms of the GNU General Public License as published by
14169695Skan   the Free Software Foundation; either version 2, or (at your option)
15169695Skan   any later version.
16169695Skan
17169695Skan   This program is distributed in the hope that it will be useful,
18169695Skan   but WITHOUT ANY WARRANTY; without even the implied warranty of
19169695Skan   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20169695Skan   GNU General Public License for more details.
21169695Skan
22169695Skan   You should have received a copy of the GNU General Public License
23169695Skan   along with this program; if not, write to the Free Software
24169695Skan   Foundation, Inc., 51 Franklin Street - Fifth Floor,
25169695Skan   Boston, MA 02110-1301, USA.
26169695Skan
27169695Skan   Written by Cygnus Support, 1994.
28169695Skan
29169695Skan   The libiberty library provides a number of functions which are
30169695Skan   missing on some operating systems.  We do not declare those here,
31169695Skan   to avoid conflicts with the system header files on operating
32169695Skan   systems that do support those functions.  In this file we only
33169695Skan   declare those functions which are specific to libiberty.  */
34169695Skan
35169695Skan#ifndef LIBIBERTY_H
36169695Skan#define LIBIBERTY_H
37169695Skan
38169695Skan#ifdef __cplusplus
39169695Skanextern "C" {
40169695Skan#endif
41169695Skan
42169695Skan#include "ansidecl.h"
43169695Skan
44169695Skan/* Get a definition for size_t.  */
45169695Skan#include <stddef.h>
46169695Skan/* Get a definition for va_list.  */
47169695Skan#include <stdarg.h>
48169695Skan
49169695Skan#include <stdio.h>
50169695Skan
51169695Skan/* If the OS supports it, ensure that the supplied stream is setup to
52169695Skan   avoid any multi-threaded locking.  Otherwise leave the FILE pointer
53169695Skan   unchanged.  If the stream is NULL do nothing.  */
54169695Skan
55169695Skanextern void unlock_stream (FILE *);
56169695Skan
57169695Skan/* If the OS supports it, ensure that the standard I/O streams, stdin,
58169695Skan   stdout and stderr are setup to avoid any multi-threaded locking.
59169695Skan   Otherwise do nothing.  */
60169695Skan
61169695Skanextern void unlock_std_streams (void);
62169695Skan
63169695Skan/* Open and return a FILE pointer.  If the OS supports it, ensure that
64169695Skan   the stream is setup to avoid any multi-threaded locking.  Otherwise
65169695Skan   return the FILE pointer unchanged.  */
66169695Skan
67169695Skanextern FILE *fopen_unlocked (const char *, const char *);
68169695Skanextern FILE *fdopen_unlocked (int, const char *);
69169695Skanextern FILE *freopen_unlocked (const char *, const char *, FILE *);
70169695Skan
71169695Skan/* Build an argument vector from a string.  Allocates memory using
72169695Skan   malloc.  Use freeargv to free the vector.  */
73169695Skan
74169695Skanextern char **buildargv (const char *) ATTRIBUTE_MALLOC;
75169695Skan
76169695Skan/* Free a vector returned by buildargv.  */
77169695Skan
78169695Skanextern void freeargv (char **);
79169695Skan
80169695Skan/* Duplicate an argument vector. Allocates memory using malloc.  Use
81169695Skan   freeargv to free the vector.  */
82169695Skan
83169695Skanextern char **dupargv (char **) ATTRIBUTE_MALLOC;
84169695Skan
85169695Skan/* Expand "@file" arguments in argv.  */
86169695Skan
87169695Skanextern void expandargv PARAMS ((int *, char ***));
88169695Skan
89169695Skan/* Return the last component of a path name.  Note that we can't use a
90169695Skan   prototype here because the parameter is declared inconsistently
91169695Skan   across different systems, sometimes as "char *" and sometimes as
92169695Skan   "const char *" */
93169695Skan
94169695Skan/* HAVE_DECL_* is a three-state macro: undefined, 0 or 1.  If it is
95169695Skan   undefined, we haven't run the autoconf check so provide the
96169695Skan   declaration without arguments.  If it is 0, we checked and failed
97169695Skan   to find the declaration so provide a fully prototyped one.  If it
98169695Skan   is 1, we found it so don't provide any declaration at all.  */
99169695Skan#if !HAVE_DECL_BASENAME
100169695Skan#if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || defined (__MINGW32__) || defined (HAVE_DECL_BASENAME)
101169695Skanextern char *basename (const char *);
102169695Skan#else
103169695Skan/* Do not allow basename to be used if there is no prototype seen.  We
104169695Skan   either need to use the above prototype or have one from
105169695Skan   autoconf which would result in HAVE_DECL_BASENAME being set.  */
106169695Skan#define basename basename_cannot_be_used_without_a_prototype
107169695Skan#endif
108169695Skan#endif
109169695Skan
110169695Skan/* A well-defined basename () that is always compiled in.  */
111169695Skan
112169695Skanextern const char *lbasename (const char *);
113169695Skan
114169695Skan/* A well-defined realpath () that is always compiled in.  */
115169695Skan
116169695Skanextern char *lrealpath (const char *);
117169695Skan
118169695Skan/* Concatenate an arbitrary number of strings.  You must pass NULL as
119169695Skan   the last argument of this function, to terminate the list of
120169695Skan   strings.  Allocates memory using xmalloc.  */
121169695Skan
122169695Skanextern char *concat (const char *, ...) ATTRIBUTE_MALLOC ATTRIBUTE_SENTINEL;
123169695Skan
124169695Skan/* Concatenate an arbitrary number of strings.  You must pass NULL as
125169695Skan   the last argument of this function, to terminate the list of
126169695Skan   strings.  Allocates memory using xmalloc.  The first argument is
127169695Skan   not one of the strings to be concatenated, but if not NULL is a
128169695Skan   pointer to be freed after the new string is created, similar to the
129169695Skan   way xrealloc works.  */
130169695Skan
131169695Skanextern char *reconcat (char *, const char *, ...) ATTRIBUTE_MALLOC ATTRIBUTE_SENTINEL;
132169695Skan
133169695Skan/* Determine the length of concatenating an arbitrary number of
134169695Skan   strings.  You must pass NULL as the last argument of this function,
135169695Skan   to terminate the list of strings.  */
136169695Skan
137169695Skanextern unsigned long concat_length (const char *, ...) ATTRIBUTE_SENTINEL;
138169695Skan
139169695Skan/* Concatenate an arbitrary number of strings into a SUPPLIED area of
140169695Skan   memory.  You must pass NULL as the last argument of this function,
141169695Skan   to terminate the list of strings.  The supplied memory is assumed
142169695Skan   to be large enough.  */
143169695Skan
144169695Skanextern char *concat_copy (char *, const char *, ...) ATTRIBUTE_SENTINEL;
145169695Skan
146169695Skan/* Concatenate an arbitrary number of strings into a GLOBAL area of
147169695Skan   memory.  You must pass NULL as the last argument of this function,
148169695Skan   to terminate the list of strings.  The supplied memory is assumed
149169695Skan   to be large enough.  */
150169695Skan
151169695Skanextern char *concat_copy2 (const char *, ...) ATTRIBUTE_SENTINEL;
152169695Skan
153169695Skan/* This is the global area used by concat_copy2.  */
154169695Skan
155169695Skanextern char *libiberty_concat_ptr;
156169695Skan
157169695Skan/* Concatenate an arbitrary number of strings.  You must pass NULL as
158169695Skan   the last argument of this function, to terminate the list of
159169695Skan   strings.  Allocates memory using alloca.  The arguments are
160169695Skan   evaluated twice!  */
161169695Skan#define ACONCAT(ACONCAT_PARAMS) \
162169695Skan  (libiberty_concat_ptr = (char *) alloca (concat_length ACONCAT_PARAMS + 1), \
163169695Skan   concat_copy2 ACONCAT_PARAMS)
164169695Skan
165169695Skan/* Check whether two file descriptors refer to the same file.  */
166169695Skan
167169695Skanextern int fdmatch (int fd1, int fd2);
168169695Skan
169169695Skan/* Return the position of the first bit set in the argument.  */
170169695Skan/* Prototypes vary from system to system, so we only provide a
171169695Skan   prototype on systems where we know that we need it.  */
172169695Skan#if defined (HAVE_DECL_FFS) && !HAVE_DECL_FFS
173169695Skanextern int ffs(int);
174169695Skan#endif
175169695Skan
176169695Skan/* Get the working directory.  The result is cached, so don't call
177169695Skan   chdir() between calls to getpwd().  */
178169695Skan
179169695Skanextern char * getpwd (void);
180169695Skan
181169695Skan/* Get the current time.  */
182169695Skan/* Prototypes vary from system to system, so we only provide a
183169695Skan   prototype on systems where we know that we need it.  */
184169695Skan#ifdef __MINGW32__
185169695Skan/* Forward declaration to avoid #include <sys/time.h>.   */
186169695Skanstruct timeval;
187169695Skanextern int gettimeofday (struct timeval *, void *);
188169695Skan#endif
189169695Skan
190169695Skan/* Get the amount of time the process has run, in microseconds.  */
191169695Skan
192169695Skanextern long get_run_time (void);
193169695Skan
194169695Skan/* Generate a relocated path to some installation directory.  Allocates
195169695Skan   return value using malloc.  */
196169695Skan
197169695Skanextern char *make_relative_prefix (const char *, const char *,
198169695Skan                                   const char *) ATTRIBUTE_MALLOC;
199169695Skan
200169695Skan/* Choose a temporary directory to use for scratch files.  */
201169695Skan
202169695Skanextern char *choose_temp_base (void) ATTRIBUTE_MALLOC;
203169695Skan
204169695Skan/* Return a temporary file name or NULL if unable to create one.  */
205169695Skan
206169695Skanextern char *make_temp_file (const char *) ATTRIBUTE_MALLOC;
207169695Skan
208169695Skan/* Remove a link to a file unless it is special. */
209169695Skan
210169695Skanextern int unlink_if_ordinary (const char *);
211169695Skan
212169695Skan/* Allocate memory filled with spaces.  Allocates using malloc.  */
213169695Skan
214169695Skanextern const char *spaces (int count);
215169695Skan
216169695Skan/* Return the maximum error number for which strerror will return a
217169695Skan   string.  */
218169695Skan
219169695Skanextern int errno_max (void);
220169695Skan
221169695Skan/* Return the name of an errno value (e.g., strerrno (EINVAL) returns
222169695Skan   "EINVAL").  */
223169695Skan
224169695Skanextern const char *strerrno (int);
225169695Skan
226169695Skan/* Given the name of an errno value, return the value.  */
227169695Skan
228169695Skanextern int strtoerrno (const char *);
229169695Skan
230169695Skan/* ANSI's strerror(), but more robust.  */
231169695Skan
232169695Skanextern char *xstrerror (int);
233169695Skan
234169695Skan/* Return the maximum signal number for which strsignal will return a
235169695Skan   string.  */
236169695Skan
237169695Skanextern int signo_max (void);
238169695Skan
239169695Skan/* Return a signal message string for a signal number
240169695Skan   (e.g., strsignal (SIGHUP) returns something like "Hangup").  */
241169695Skan/* This is commented out as it can conflict with one in system headers.
242169695Skan   We still document its existence though.  */
243169695Skan
244169695Skan/*extern const char *strsignal (int);*/
245169695Skan
246169695Skan/* Return the name of a signal number (e.g., strsigno (SIGHUP) returns
247169695Skan   "SIGHUP").  */
248169695Skan
249169695Skanextern const char *strsigno (int);
250169695Skan
251169695Skan/* Given the name of a signal, return its number.  */
252169695Skan
253169695Skanextern int strtosigno (const char *);
254169695Skan
255169695Skan/* Register a function to be run by xexit.  Returns 0 on success.  */
256169695Skan
257169695Skanextern int xatexit (void (*fn) (void));
258169695Skan
259169695Skan/* Exit, calling all the functions registered with xatexit.  */
260169695Skan
261169695Skanextern void xexit (int status) ATTRIBUTE_NORETURN;
262169695Skan
263169695Skan/* Set the program name used by xmalloc.  */
264169695Skan
265169695Skanextern void xmalloc_set_program_name (const char *);
266169695Skan
267169695Skan/* Report an allocation failure.  */
268169695Skanextern void xmalloc_failed (size_t) ATTRIBUTE_NORETURN;
269169695Skan
270169695Skan/* Allocate memory without fail.  If malloc fails, this will print a
271169695Skan   message to stderr (using the name set by xmalloc_set_program_name,
272169695Skan   if any) and then call xexit.  */
273169695Skan
274169695Skanextern void *xmalloc (size_t) ATTRIBUTE_MALLOC;
275169695Skan
276169695Skan/* Reallocate memory without fail.  This works like xmalloc.  Note,
277169695Skan   realloc type functions are not suitable for attribute malloc since
278169695Skan   they may return the same address across multiple calls. */
279169695Skan
280169695Skanextern void *xrealloc (void *, size_t);
281169695Skan
282169695Skan/* Allocate memory without fail and set it to zero.  This works like
283169695Skan   xmalloc.  */
284169695Skan
285169695Skanextern void *xcalloc (size_t, size_t) ATTRIBUTE_MALLOC;
286169695Skan
287169695Skan/* Copy a string into a memory buffer without fail.  */
288169695Skan
289169695Skanextern char *xstrdup (const char *) ATTRIBUTE_MALLOC;
290169695Skan
291169695Skan/* Copy at most N characters from string into a buffer without fail.  */
292169695Skan
293169695Skanextern char *xstrndup (const char *, size_t) ATTRIBUTE_MALLOC;
294169695Skan
295169695Skan/* Copy an existing memory buffer to a new memory buffer without fail.  */
296169695Skan
297169695Skanextern void *xmemdup (const void *, size_t, size_t) ATTRIBUTE_MALLOC;
298169695Skan
299169695Skan/* Physical memory routines.  Return values are in BYTES.  */
300169695Skanextern double physmem_total (void);
301169695Skanextern double physmem_available (void);
302169695Skan
303169695Skan
304169695Skan/* These macros provide a K&R/C89/C++-friendly way of allocating structures
305169695Skan   with nice encapsulation.  The XDELETE*() macros are technically
306169695Skan   superfluous, but provided here for symmetry.  Using them consistently
307169695Skan   makes it easier to update client code to use different allocators such
308169695Skan   as new/delete and new[]/delete[].  */
309169695Skan
310169695Skan/* Scalar allocators.  */
311169695Skan
312169695Skan#define XNEW(T)			((T *) xmalloc (sizeof (T)))
313169695Skan#define XCNEW(T)		((T *) xcalloc (1, sizeof (T)))
314169695Skan#define XDELETE(P)		free ((void*) (P))
315169695Skan
316169695Skan/* Array allocators.  */
317169695Skan
318169695Skan#define XNEWVEC(T, N)		((T *) xmalloc (sizeof (T) * (N)))
319169695Skan#define XCNEWVEC(T, N)		((T *) xcalloc ((N), sizeof (T)))
320169695Skan#define XRESIZEVEC(T, P, N)	((T *) xrealloc ((void *) (P), sizeof (T) * (N)))
321169695Skan#define XDELETEVEC(P)		free ((void*) (P))
322169695Skan
323169695Skan/* Allocators for variable-sized structures and raw buffers.  */
324169695Skan
325169695Skan#define XNEWVAR(T, S)		((T *) xmalloc ((S)))
326169695Skan#define XCNEWVAR(T, S)		((T *) xcalloc (1, (S)))
327169695Skan#define XRESIZEVAR(T, P, S)	((T *) xrealloc ((P), (S)))
328169695Skan
329169695Skan/* Type-safe obstack allocator.  */
330169695Skan
331169695Skan#define XOBNEW(O, T)		((T *) obstack_alloc ((O), sizeof (T)))
332169695Skan#define XOBFINISH(O, T)         ((T) obstack_finish ((O)))
333169695Skan
334169695Skan/* hex character manipulation routines */
335169695Skan
336169695Skan#define _hex_array_size 256
337169695Skan#define _hex_bad	99
338169695Skanextern const unsigned char _hex_value[_hex_array_size];
339169695Skanextern void hex_init (void);
340169695Skan#define hex_p(c)	(hex_value (c) != _hex_bad)
341169695Skan/* If you change this, note well: Some code relies on side effects in
342169695Skan   the argument being performed exactly once.  */
343169695Skan#define hex_value(c)	((unsigned int) _hex_value[(unsigned char) (c)])
344169695Skan
345169695Skan/* Flags for pex_init.  These are bits to be or'ed together.  */
346169695Skan
347169695Skan/* Record subprocess times, if possible.  */
348169695Skan#define PEX_RECORD_TIMES	0x1
349169695Skan
350169695Skan/* Use pipes for communication between processes, if possible.  */
351169695Skan#define PEX_USE_PIPES		0x2
352169695Skan
353169695Skan/* Save files used for communication between processes.  */
354169695Skan#define PEX_SAVE_TEMPS		0x4
355169695Skan
356169695Skan/* Prepare to execute one or more programs, with standard output of
357169695Skan   each program fed to standard input of the next.
358169695Skan   FLAGS	As above.
359169695Skan   PNAME	The name of the program to report in error messages.
360169695Skan   TEMPBASE	A base name to use for temporary files; may be NULL to
361169695Skan   		use a random name.
362169695Skan   Returns NULL on error.  */
363169695Skan
364169695Skanextern struct pex_obj *pex_init (int flags, const char *pname,
365169695Skan				 const char *tempbase);
366169695Skan
367169695Skan/* Flags for pex_run.  These are bits to be or'ed together.  */
368169695Skan
369169695Skan/* Last program in pipeline.  Standard output of program goes to
370169695Skan   OUTNAME, or, if OUTNAME is NULL, to standard output of caller.  Do
371169695Skan   not set this if you want to call pex_read_output.  After this is
372169695Skan   set, pex_run may no longer be called with the same struct
373169695Skan   pex_obj.  */
374169695Skan#define PEX_LAST		0x1
375169695Skan
376169695Skan/* Search for program in executable search path.  */
377169695Skan#define PEX_SEARCH		0x2
378169695Skan
379169695Skan/* OUTNAME is a suffix.  */
380169695Skan#define PEX_SUFFIX		0x4
381169695Skan
382169695Skan/* Send program's standard error to standard output.  */
383169695Skan#define PEX_STDERR_TO_STDOUT	0x8
384169695Skan
385169695Skan/* Input file should be opened in binary mode.  This flag is ignored
386169695Skan   on Unix.  */
387169695Skan#define PEX_BINARY_INPUT	0x10
388169695Skan
389169695Skan/* Output file should be opened in binary mode.  This flag is ignored
390169695Skan   on Unix.  For proper behaviour PEX_BINARY_INPUT and
391169695Skan   PEX_BINARY_OUTPUT have to match appropriately--i.e., a call using
392169695Skan   PEX_BINARY_OUTPUT should be followed by a call using
393169695Skan   PEX_BINARY_INPUT.  */
394169695Skan#define PEX_BINARY_OUTPUT	0x20
395169695Skan
396169695Skan/* Execute one program.  Returns NULL on success.  On error returns an
397169695Skan   error string (typically just the name of a system call); the error
398169695Skan   string is statically allocated.
399169695Skan
400169695Skan   OBJ		Returned by pex_init.
401169695Skan
402169695Skan   FLAGS	As above.
403169695Skan
404169695Skan   EXECUTABLE	The program to execute.
405169695Skan
406169695Skan   ARGV		NULL terminated array of arguments to pass to the program.
407169695Skan
408169695Skan   OUTNAME	Sets the output file name as follows:
409169695Skan
410169695Skan		PEX_SUFFIX set (OUTNAME may not be NULL):
411169695Skan		  TEMPBASE parameter to pex_init not NULL:
412169695Skan		    Output file name is the concatenation of TEMPBASE
413169695Skan		    and OUTNAME.
414169695Skan		  TEMPBASE is NULL:
415169695Skan		    Output file name is a random file name ending in
416169695Skan		    OUTNAME.
417169695Skan		PEX_SUFFIX not set:
418169695Skan		  OUTNAME not NULL:
419169695Skan		    Output file name is OUTNAME.
420169695Skan		  OUTNAME NULL, TEMPBASE not NULL:
421169695Skan		    Output file name is randomly chosen using
422169695Skan		    TEMPBASE.
423169695Skan		  OUTNAME NULL, TEMPBASE NULL:
424169695Skan		    Output file name is randomly chosen.
425169695Skan
426169695Skan		If PEX_LAST is not set, the output file name is the
427169695Skan   		name to use for a temporary file holding stdout, if
428169695Skan   		any (there will not be a file if PEX_USE_PIPES is set
429169695Skan   		and the system supports pipes).  If a file is used, it
430169695Skan   		will be removed when no longer needed unless
431169695Skan   		PEX_SAVE_TEMPS is set.
432169695Skan
433169695Skan		If PEX_LAST is set, and OUTNAME is not NULL, standard
434169695Skan   		output is written to the output file name.  The file
435169695Skan   		will not be removed.  If PEX_LAST and PEX_SUFFIX are
436169695Skan   		both set, TEMPBASE may not be NULL.
437169695Skan
438169695Skan   ERRNAME	If not NULL, this is the name of a file to which
439169695Skan		standard error is written.  If NULL, standard error of
440169695Skan		the program is standard error of the caller.
441169695Skan
442169695Skan   ERR		On an error return, *ERR is set to an errno value, or
443169695Skan   		to 0 if there is no relevant errno.
444169695Skan*/
445169695Skan
446169695Skanextern const char *pex_run (struct pex_obj *obj, int flags,
447169695Skan			    const char *executable, char * const *argv,
448169695Skan			    const char *outname, const char *errname,
449169695Skan			    int *err);
450169695Skan
451169695Skan/* As for pex_run (), but takes an extra parameter to enable the
452169695Skan   environment for the child process to be specified.
453169695Skan
454169695Skan   ENV		The environment for the child process, specified as
455169695Skan		an array of character pointers.  Each element of the
456169695Skan		array should point to a string of the form VAR=VALUE,
457169695Skan                with the exception of the last element which must be
458169695Skan                a null pointer.
459169695Skan*/
460169695Skan
461169695Skanextern const char *pex_run_in_environment (struct pex_obj *obj, int flags,
462169695Skan			                   const char *executable,
463169695Skan                                           char * const *argv,
464169695Skan                                           char * const *env,
465169695Skan              	          		   const char *outname,
466169695Skan					   const char *errname, int *err);
467169695Skan
468169695Skan/* Return a stream for a temporary file to pass to the first program
469169695Skan   in the pipeline as input.  The file name is chosen as for pex_run.
470169695Skan   pex_run closes the file automatically; don't close it yourself.  */
471169695Skan
472169695Skanextern FILE *pex_input_file (struct pex_obj *obj, int flags,
473169695Skan                             const char *in_name);
474169695Skan
475169695Skan/* Return a stream for a pipe connected to the standard input of the
476169695Skan   first program in the pipeline.  You must have passed
477169695Skan   `PEX_USE_PIPES' to `pex_init'.  Close the returned stream
478169695Skan   yourself.  */
479169695Skan
480169695Skanextern FILE *pex_input_pipe (struct pex_obj *obj, int binary);
481169695Skan
482169695Skan/* Read the standard output of the last program to be executed.
483169695Skan   pex_run can not be called after this.  BINARY should be non-zero if
484169695Skan   the file should be opened in binary mode; this is ignored on Unix.
485169695Skan   Returns NULL on error.  Don't call fclose on the returned FILE; it
486169695Skan   will be closed by pex_free.  */
487169695Skan
488169695Skanextern FILE *pex_read_output (struct pex_obj *, int binary);
489169695Skan
490169695Skan/* Return exit status of all programs in VECTOR.  COUNT indicates the
491169695Skan   size of VECTOR.  The status codes in the vector are in the order of
492169695Skan   the calls to pex_run.  Returns 0 on error, 1 on success.  */
493169695Skan
494169695Skanextern int pex_get_status (struct pex_obj *, int count, int *vector);
495169695Skan
496169695Skan/* Return times of all programs in VECTOR.  COUNT indicates the size
497169695Skan   of VECTOR.  struct pex_time is really just struct timeval, but that
498169695Skan   is not portable to all systems.  Returns 0 on error, 1 on
499169695Skan   success.  */
500169695Skan
501169695Skanstruct pex_time
502169695Skan{
503169695Skan  unsigned long user_seconds;
504169695Skan  unsigned long user_microseconds;
505169695Skan  unsigned long system_seconds;
506169695Skan  unsigned long system_microseconds;
507169695Skan};
508169695Skan
509169695Skanextern int pex_get_times (struct pex_obj *, int count,
510169695Skan			  struct pex_time *vector);
511169695Skan
512169695Skan/* Clean up a pex_obj.  */
513169695Skan
514169695Skanextern void pex_free (struct pex_obj *);
515169695Skan
516169695Skan/* Just execute one program.  Return value is as for pex_run.
517169695Skan   FLAGS	Combination of PEX_SEARCH and PEX_STDERR_TO_STDOUT.
518169695Skan   EXECUTABLE	As for pex_run.
519169695Skan   ARGV		As for pex_run.
520169695Skan   PNAME	As for pex_init.
521169695Skan   OUTNAME	As for pex_run when PEX_LAST is set.
522169695Skan   ERRNAME	As for pex_run.
523169695Skan   STATUS	Set to exit status on success.
524169695Skan   ERR		As for pex_run.
525169695Skan*/
526169695Skan
527169695Skanextern const char *pex_one (int flags, const char *executable,
528169695Skan			    char * const *argv, const char *pname,
529169695Skan			    const char *outname, const char *errname,
530169695Skan			    int *status, int *err);
531169695Skan
532169695Skan/* pexecute and pwait are the old pexecute interface, still here for
533169695Skan   backward compatibility.  Don't use these for new code.  Instead,
534169695Skan   use pex_init/pex_run/pex_get_status/pex_free, or pex_one.  */
535169695Skan
536169695Skan/* Definitions used by the pexecute routine.  */
537169695Skan
538169695Skan#define PEXECUTE_FIRST   1
539169695Skan#define PEXECUTE_LAST    2
540169695Skan#define PEXECUTE_ONE     (PEXECUTE_FIRST + PEXECUTE_LAST)
541169695Skan#define PEXECUTE_SEARCH  4
542169695Skan#define PEXECUTE_VERBOSE 8
543169695Skan
544169695Skan/* Execute a program.  */
545169695Skan
546169695Skanextern int pexecute (const char *, char * const *, const char *,
547169695Skan                     const char *, char **, char **, int);
548169695Skan
549169695Skan/* Wait for pexecute to finish.  */
550169695Skan
551169695Skanextern int pwait (int, int *, int);
552169695Skan
553169695Skan#if !HAVE_DECL_ASPRINTF
554169695Skan/* Like sprintf but provides a pointer to malloc'd storage, which must
555169695Skan   be freed by the caller.  */
556169695Skan
557169695Skanextern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2;
558169695Skan#endif
559169695Skan
560169695Skan#if !HAVE_DECL_VASPRINTF
561169695Skan/* Like vsprintf but provides a pointer to malloc'd storage, which
562169695Skan   must be freed by the caller.  */
563169695Skan
564169695Skanextern int vasprintf (char **, const char *, va_list) ATTRIBUTE_PRINTF(2,0);
565169695Skan#endif
566169695Skan
567169695Skan#if defined(HAVE_DECL_SNPRINTF) && !HAVE_DECL_SNPRINTF
568169695Skan/* Like sprintf but prints at most N characters.  */
569169695Skanextern int snprintf (char *, size_t, const char *, ...) ATTRIBUTE_PRINTF_3;
570169695Skan#endif
571169695Skan
572169695Skan#if defined(HAVE_DECL_VSNPRINTF) && !HAVE_DECL_VSNPRINTF
573169695Skan/* Like vsprintf but prints at most N characters.  */
574169695Skanextern int vsnprintf (char *, size_t, const char *, va_list) ATTRIBUTE_PRINTF(3,0);
575169695Skan#endif
576169695Skan
577169695Skan#if defined(HAVE_DECL_STRVERSCMP) && !HAVE_DECL_STRVERSCMP
578169695Skan/* Compare version strings.  */
579169695Skanextern int strverscmp (const char *, const char *);
580169695Skan#endif
581169695Skan
582169695Skan#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
583169695Skan
584169695Skan/* Drastically simplified alloca configurator.  If we're using GCC,
585169695Skan   we use __builtin_alloca; otherwise we use the C alloca.  The C
586169695Skan   alloca is always available.  You can override GCC by defining
587169695Skan   USE_C_ALLOCA yourself.  The canonical autoconf macro C_ALLOCA is
588169695Skan   also set/unset as it is often used to indicate whether code needs
589169695Skan   to call alloca(0).  */
590169695Skanextern void *C_alloca (size_t) ATTRIBUTE_MALLOC;
591169695Skan#undef alloca
592169695Skan#if GCC_VERSION >= 2000 && !defined USE_C_ALLOCA
593169695Skan# define alloca(x) __builtin_alloca(x)
594169695Skan# undef C_ALLOCA
595169695Skan# define ASTRDUP(X) \
596169695Skan  (__extension__ ({ const char *const libiberty_optr = (X); \
597169695Skan   const unsigned long libiberty_len = strlen (libiberty_optr) + 1; \
598169695Skan   char *const libiberty_nptr = (char *const) alloca (libiberty_len); \
599169695Skan   (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len); }))
600169695Skan#else
601169695Skan# define alloca(x) C_alloca(x)
602169695Skan# undef USE_C_ALLOCA
603169695Skan# define USE_C_ALLOCA 1
604169695Skan# undef C_ALLOCA
605169695Skan# define C_ALLOCA 1
606169695Skanextern const char *libiberty_optr;
607169695Skanextern char *libiberty_nptr;
608169695Skanextern unsigned long libiberty_len;
609169695Skan# define ASTRDUP(X) \
610169695Skan  (libiberty_optr = (X), \
611169695Skan   libiberty_len = strlen (libiberty_optr) + 1, \
612169695Skan   libiberty_nptr = (char *) alloca (libiberty_len), \
613169695Skan   (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len))
614169695Skan#endif
615169695Skan
616169695Skan#ifdef __cplusplus
617169695Skan}
618169695Skan#endif
619169695Skan
620169695Skan
621169695Skan#endif /* ! defined (LIBIBERTY_H) */
622