133965Sjdp/* Function declarations for libiberty. 278828Sobrien 3218822Sdim Copyright 2001, 2002, 2005 Free Software Foundation, Inc. 478828Sobrien 578828Sobrien Note - certain prototypes declared in this header file are for 678828Sobrien functions whoes implementation copyright does not belong to the 778828Sobrien FSF. Those prototypes are present in this file for reference 878828Sobrien purposes only and their presence in this file should not construed 978828Sobrien as an indication of ownership by the FSF of the implementation of 1078828Sobrien those functions in any way or form whatsoever. 1178828Sobrien 1278828Sobrien This program is free software; you can redistribute it and/or modify 1378828Sobrien it under the terms of the GNU General Public License as published by 1478828Sobrien the Free Software Foundation; either version 2, or (at your option) 1578828Sobrien any later version. 1678828Sobrien 1778828Sobrien This program is distributed in the hope that it will be useful, 1878828Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 1978828Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2078828Sobrien GNU General Public License for more details. 2178828Sobrien 2278828Sobrien You should have received a copy of the GNU General Public License 2378828Sobrien along with this program; if not, write to the Free Software 24218822Sdim Foundation, Inc., 51 Franklin Street - Fifth Floor, 25218822Sdim Boston, MA 02110-1301, USA. 2678828Sobrien 2733965Sjdp Written by Cygnus Support, 1994. 2833965Sjdp 2933965Sjdp The libiberty library provides a number of functions which are 3033965Sjdp missing on some operating systems. We do not declare those here, 3133965Sjdp to avoid conflicts with the system header files on operating 3233965Sjdp systems that do support those functions. In this file we only 3333965Sjdp declare those functions which are specific to libiberty. */ 3433965Sjdp 3533965Sjdp#ifndef LIBIBERTY_H 3633965Sjdp#define LIBIBERTY_H 3733965Sjdp 3838889Sjdp#ifdef __cplusplus 3938889Sjdpextern "C" { 4038889Sjdp#endif 4138889Sjdp 4233965Sjdp#include "ansidecl.h" 4333965Sjdp 4477298Sobrien/* Get a definition for size_t. */ 4577298Sobrien#include <stddef.h> 4677298Sobrien/* Get a definition for va_list. */ 4777298Sobrien#include <stdarg.h> 4877298Sobrien 49218822Sdim#include <stdio.h> 50218822Sdim 51218822Sdim/* If the OS supports it, ensure that the supplied stream is setup to 52218822Sdim avoid any multi-threaded locking. Otherwise leave the FILE pointer 53218822Sdim unchanged. If the stream is NULL do nothing. */ 54218822Sdim 55218822Sdimextern void unlock_stream (FILE *); 56218822Sdim 57218822Sdim/* If the OS supports it, ensure that the standard I/O streams, stdin, 58218822Sdim stdout and stderr are setup to avoid any multi-threaded locking. 59218822Sdim Otherwise do nothing. */ 60218822Sdim 61218822Sdimextern void unlock_std_streams (void); 62218822Sdim 63218822Sdim/* Open and return a FILE pointer. If the OS supports it, ensure that 64218822Sdim the stream is setup to avoid any multi-threaded locking. Otherwise 65218822Sdim return the FILE pointer unchanged. */ 66218822Sdim 67218822Sdimextern FILE *fopen_unlocked (const char *, const char *); 68218822Sdimextern FILE *fdopen_unlocked (int, const char *); 69218822Sdimextern FILE *freopen_unlocked (const char *, const char *, FILE *); 70218822Sdim 7133965Sjdp/* Build an argument vector from a string. Allocates memory using 7233965Sjdp malloc. Use freeargv to free the vector. */ 7333965Sjdp 74218822Sdimextern char **buildargv (const char *) ATTRIBUTE_MALLOC; 7533965Sjdp 7633965Sjdp/* Free a vector returned by buildargv. */ 7733965Sjdp 78218822Sdimextern void freeargv (char **); 7933965Sjdp 8038889Sjdp/* Duplicate an argument vector. Allocates memory using malloc. Use 8138889Sjdp freeargv to free the vector. */ 8238889Sjdp 83218822Sdimextern char **dupargv (char **) ATTRIBUTE_MALLOC; 8438889Sjdp 85218822Sdim/* Expand "@file" arguments in argv. */ 8638889Sjdp 87218822Sdimextern void expandargv PARAMS ((int *, char ***)); 88218822Sdim 89218822Sdim/* Write argv to an @-file, inserting necessary quoting. */ 90218822Sdim 91218822Sdimextern int writeargv PARAMS ((char **, FILE *)); 92218822Sdim 9333965Sjdp/* Return the last component of a path name. Note that we can't use a 9433965Sjdp prototype here because the parameter is declared inconsistently 9533965Sjdp across different systems, sometimes as "char *" and sometimes as 9633965Sjdp "const char *" */ 9733965Sjdp 9877298Sobrien/* HAVE_DECL_* is a three-state macro: undefined, 0 or 1. If it is 9977298Sobrien undefined, we haven't run the autoconf check so provide the 10077298Sobrien declaration without arguments. If it is 0, we checked and failed 10177298Sobrien to find the declaration so provide a fully prototyped one. If it 10277298Sobrien is 1, we found it so don't provide any declaration at all. */ 103104834Sobrien#if !HAVE_DECL_BASENAME 104218822Sdim#if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || defined (__MINGW32__) || defined (HAVE_DECL_BASENAME) 105218822Sdimextern char *basename (const char *); 10633965Sjdp#else 107218822Sdim/* Do not allow basename to be used if there is no prototype seen. We 108218822Sdim either need to use the above prototype or have one from 109218822Sdim autoconf which would result in HAVE_DECL_BASENAME being set. */ 110218822Sdim#define basename basename_cannot_be_used_without_a_prototype 11133965Sjdp#endif 112104834Sobrien#endif 11333965Sjdp 11480016Sobrien/* A well-defined basename () that is always compiled in. */ 11580016Sobrien 116218822Sdimextern const char *lbasename (const char *); 11780016Sobrien 118130561Sobrien/* A well-defined realpath () that is always compiled in. */ 119130561Sobrien 120218822Sdimextern char *lrealpath (const char *); 121130561Sobrien 12289857Sobrien/* Concatenate an arbitrary number of strings. You must pass NULL as 12389857Sobrien the last argument of this function, to terminate the list of 12489857Sobrien strings. Allocates memory using xmalloc. */ 12533965Sjdp 126218822Sdimextern char *concat (const char *, ...) ATTRIBUTE_MALLOC ATTRIBUTE_SENTINEL; 12733965Sjdp 12889857Sobrien/* Concatenate an arbitrary number of strings. You must pass NULL as 12989857Sobrien the last argument of this function, to terminate the list of 13089857Sobrien strings. Allocates memory using xmalloc. The first argument is 13189857Sobrien not one of the strings to be concatenated, but if not NULL is a 13289857Sobrien pointer to be freed after the new string is created, similar to the 13389857Sobrien way xrealloc works. */ 13489857Sobrien 135218822Sdimextern char *reconcat (char *, const char *, ...) ATTRIBUTE_MALLOC ATTRIBUTE_SENTINEL; 13689857Sobrien 13789857Sobrien/* Determine the length of concatenating an arbitrary number of 13889857Sobrien strings. You must pass NULL as the last argument of this function, 13989857Sobrien to terminate the list of strings. */ 14089857Sobrien 141218822Sdimextern unsigned long concat_length (const char *, ...) ATTRIBUTE_SENTINEL; 14289857Sobrien 14389857Sobrien/* Concatenate an arbitrary number of strings into a SUPPLIED area of 14489857Sobrien memory. You must pass NULL as the last argument of this function, 14589857Sobrien to terminate the list of strings. The supplied memory is assumed 14689857Sobrien to be large enough. */ 14789857Sobrien 148218822Sdimextern char *concat_copy (char *, const char *, ...) ATTRIBUTE_SENTINEL; 14989857Sobrien 15089857Sobrien/* Concatenate an arbitrary number of strings into a GLOBAL area of 15189857Sobrien memory. You must pass NULL as the last argument of this function, 15289857Sobrien to terminate the list of strings. The supplied memory is assumed 15389857Sobrien to be large enough. */ 15489857Sobrien 155218822Sdimextern char *concat_copy2 (const char *, ...) ATTRIBUTE_SENTINEL; 15689857Sobrien 15789857Sobrien/* This is the global area used by concat_copy2. */ 15889857Sobrien 15989857Sobrienextern char *libiberty_concat_ptr; 16089857Sobrien 16189857Sobrien/* Concatenate an arbitrary number of strings. You must pass NULL as 16289857Sobrien the last argument of this function, to terminate the list of 16389857Sobrien strings. Allocates memory using alloca. The arguments are 16489857Sobrien evaluated twice! */ 16589857Sobrien#define ACONCAT(ACONCAT_PARAMS) \ 166218822Sdim (libiberty_concat_ptr = (char *) alloca (concat_length ACONCAT_PARAMS + 1), \ 16789857Sobrien concat_copy2 ACONCAT_PARAMS) 16889857Sobrien 16933965Sjdp/* Check whether two file descriptors refer to the same file. */ 17033965Sjdp 171218822Sdimextern int fdmatch (int fd1, int fd2); 17233965Sjdp 173218822Sdim/* Return the position of the first bit set in the argument. */ 174218822Sdim/* Prototypes vary from system to system, so we only provide a 175218822Sdim prototype on systems where we know that we need it. */ 176218822Sdim#if defined (HAVE_DECL_FFS) && !HAVE_DECL_FFS 177218822Sdimextern int ffs(int); 178218822Sdim#endif 179218822Sdim 18060484Sobrien/* Get the working directory. The result is cached, so don't call 18160484Sobrien chdir() between calls to getpwd(). */ 18260484Sobrien 183218822Sdimextern char * getpwd (void); 18460484Sobrien 185218822Sdim/* Get the current time. */ 186218822Sdim/* Prototypes vary from system to system, so we only provide a 187218822Sdim prototype on systems where we know that we need it. */ 188218822Sdim#ifdef __MINGW32__ 189218822Sdim/* Forward declaration to avoid #include <sys/time.h>. */ 190218822Sdimstruct timeval; 191218822Sdimextern int gettimeofday (struct timeval *, void *); 192218822Sdim#endif 193218822Sdim 19433965Sjdp/* Get the amount of time the process has run, in microseconds. */ 19533965Sjdp 196218822Sdimextern long get_run_time (void); 19733965Sjdp 198130561Sobrien/* Generate a relocated path to some installation directory. Allocates 199130561Sobrien return value using malloc. */ 200130561Sobrien 201218822Sdimextern char *make_relative_prefix (const char *, const char *, 202218822Sdim const char *) ATTRIBUTE_MALLOC; 203130561Sobrien 204218822Sdim/* Generate a relocated path to some installation directory without 205218822Sdim attempting to follow any soft links. Allocates 206218822Sdim return value using malloc. */ 207218822Sdim 208218822Sdimextern char *make_relative_prefix_ignore_links (const char *, const char *, 209218822Sdim const char *) ATTRIBUTE_MALLOC; 210218822Sdim 21133965Sjdp/* Choose a temporary directory to use for scratch files. */ 21233965Sjdp 213218822Sdimextern char *choose_temp_base (void) ATTRIBUTE_MALLOC; 21433965Sjdp 21560484Sobrien/* Return a temporary file name or NULL if unable to create one. */ 21660484Sobrien 217218822Sdimextern char *make_temp_file (const char *) ATTRIBUTE_MALLOC; 21860484Sobrien 219218822Sdim/* Remove a link to a file unless it is special. */ 220218822Sdim 221218822Sdimextern int unlink_if_ordinary (const char *); 222218822Sdim 22333965Sjdp/* Allocate memory filled with spaces. Allocates using malloc. */ 22433965Sjdp 225218822Sdimextern const char *spaces (int count); 22633965Sjdp 22733965Sjdp/* Return the maximum error number for which strerror will return a 22833965Sjdp string. */ 22933965Sjdp 230218822Sdimextern int errno_max (void); 23133965Sjdp 23233965Sjdp/* Return the name of an errno value (e.g., strerrno (EINVAL) returns 23333965Sjdp "EINVAL"). */ 23433965Sjdp 235218822Sdimextern const char *strerrno (int); 23633965Sjdp 23733965Sjdp/* Given the name of an errno value, return the value. */ 23833965Sjdp 239218822Sdimextern int strtoerrno (const char *); 24033965Sjdp 24133965Sjdp/* ANSI's strerror(), but more robust. */ 24233965Sjdp 243218822Sdimextern char *xstrerror (int); 24433965Sjdp 24533965Sjdp/* Return the maximum signal number for which strsignal will return a 24633965Sjdp string. */ 24733965Sjdp 248218822Sdimextern int signo_max (void); 24933965Sjdp 25033965Sjdp/* Return a signal message string for a signal number 25133965Sjdp (e.g., strsignal (SIGHUP) returns something like "Hangup"). */ 25233965Sjdp/* This is commented out as it can conflict with one in system headers. 25333965Sjdp We still document its existence though. */ 25433965Sjdp 255218822Sdim/*extern const char *strsignal (int);*/ 25633965Sjdp 25733965Sjdp/* Return the name of a signal number (e.g., strsigno (SIGHUP) returns 25833965Sjdp "SIGHUP"). */ 25933965Sjdp 260218822Sdimextern const char *strsigno (int); 26133965Sjdp 26233965Sjdp/* Given the name of a signal, return its number. */ 26333965Sjdp 264218822Sdimextern int strtosigno (const char *); 26533965Sjdp 26633965Sjdp/* Register a function to be run by xexit. Returns 0 on success. */ 26733965Sjdp 268218822Sdimextern int xatexit (void (*fn) (void)); 26933965Sjdp 27033965Sjdp/* Exit, calling all the functions registered with xatexit. */ 27133965Sjdp 272218822Sdimextern void xexit (int status) ATTRIBUTE_NORETURN; 27333965Sjdp 27433965Sjdp/* Set the program name used by xmalloc. */ 27533965Sjdp 276218822Sdimextern void xmalloc_set_program_name (const char *); 27733965Sjdp 27877298Sobrien/* Report an allocation failure. */ 279218822Sdimextern void xmalloc_failed (size_t) ATTRIBUTE_NORETURN; 28077298Sobrien 28133965Sjdp/* Allocate memory without fail. If malloc fails, this will print a 28233965Sjdp message to stderr (using the name set by xmalloc_set_program_name, 28333965Sjdp if any) and then call xexit. */ 28433965Sjdp 285218822Sdimextern void *xmalloc (size_t) ATTRIBUTE_MALLOC; 28633965Sjdp 28760484Sobrien/* Reallocate memory without fail. This works like xmalloc. Note, 28860484Sobrien realloc type functions are not suitable for attribute malloc since 28960484Sobrien they may return the same address across multiple calls. */ 29033965Sjdp 291218822Sdimextern void *xrealloc (void *, size_t); 29260484Sobrien 29360484Sobrien/* Allocate memory without fail and set it to zero. This works like 29433965Sjdp xmalloc. */ 29533965Sjdp 296218822Sdimextern void *xcalloc (size_t, size_t) ATTRIBUTE_MALLOC; 29733965Sjdp 29833965Sjdp/* Copy a string into a memory buffer without fail. */ 29933965Sjdp 300218822Sdimextern char *xstrdup (const char *) ATTRIBUTE_MALLOC; 30133965Sjdp 302218822Sdim/* Copy at most N characters from string into a buffer without fail. */ 303218822Sdim 304218822Sdimextern char *xstrndup (const char *, size_t) ATTRIBUTE_MALLOC; 305218822Sdim 30660484Sobrien/* Copy an existing memory buffer to a new memory buffer without fail. */ 30760484Sobrien 308218822Sdimextern void *xmemdup (const void *, size_t, size_t) ATTRIBUTE_MALLOC; 30960484Sobrien 310130561Sobrien/* Physical memory routines. Return values are in BYTES. */ 311218822Sdimextern double physmem_total (void); 312218822Sdimextern double physmem_available (void); 313130561Sobrien 314218822Sdim 315218822Sdim/* These macros provide a K&R/C89/C++-friendly way of allocating structures 316218822Sdim with nice encapsulation. The XDELETE*() macros are technically 317218822Sdim superfluous, but provided here for symmetry. Using them consistently 318218822Sdim makes it easier to update client code to use different allocators such 319218822Sdim as new/delete and new[]/delete[]. */ 320218822Sdim 321218822Sdim/* Scalar allocators. */ 322218822Sdim 323218822Sdim#define XNEW(T) ((T *) xmalloc (sizeof (T))) 324218822Sdim#define XCNEW(T) ((T *) xcalloc (1, sizeof (T))) 325218822Sdim#define XDELETE(P) free ((void*) (P)) 326218822Sdim 327218822Sdim/* Array allocators. */ 328218822Sdim 329218822Sdim#define XNEWVEC(T, N) ((T *) xmalloc (sizeof (T) * (N))) 330218822Sdim#define XCNEWVEC(T, N) ((T *) xcalloc ((N), sizeof (T))) 331218822Sdim#define XRESIZEVEC(T, P, N) ((T *) xrealloc ((void *) (P), sizeof (T) * (N))) 332218822Sdim#define XDELETEVEC(P) free ((void*) (P)) 333218822Sdim 334218822Sdim/* Allocators for variable-sized structures and raw buffers. */ 335218822Sdim 336218822Sdim#define XNEWVAR(T, S) ((T *) xmalloc ((S))) 337218822Sdim#define XCNEWVAR(T, S) ((T *) xcalloc (1, (S))) 338218822Sdim#define XRESIZEVAR(T, P, S) ((T *) xrealloc ((P), (S))) 339218822Sdim 340218822Sdim/* Type-safe obstack allocator. */ 341218822Sdim 342218822Sdim#define XOBNEW(O, T) ((T *) obstack_alloc ((O), sizeof (T))) 343218822Sdim#define XOBFINISH(O, T) ((T) obstack_finish ((O))) 344218822Sdim 34533965Sjdp/* hex character manipulation routines */ 34633965Sjdp 34733965Sjdp#define _hex_array_size 256 34833965Sjdp#define _hex_bad 99 349130561Sobrienextern const unsigned char _hex_value[_hex_array_size]; 350218822Sdimextern void hex_init (void); 35133965Sjdp#define hex_p(c) (hex_value (c) != _hex_bad) 35233965Sjdp/* If you change this, note well: Some code relies on side effects in 35333965Sjdp the argument being performed exactly once. */ 354130561Sobrien#define hex_value(c) ((unsigned int) _hex_value[(unsigned char) (c)]) 35533965Sjdp 356218822Sdim/* Flags for pex_init. These are bits to be or'ed together. */ 357218822Sdim 358218822Sdim/* Record subprocess times, if possible. */ 359218822Sdim#define PEX_RECORD_TIMES 0x1 360218822Sdim 361218822Sdim/* Use pipes for communication between processes, if possible. */ 362218822Sdim#define PEX_USE_PIPES 0x2 363218822Sdim 364218822Sdim/* Save files used for communication between processes. */ 365218822Sdim#define PEX_SAVE_TEMPS 0x4 366218822Sdim 367218822Sdim/* Prepare to execute one or more programs, with standard output of 368218822Sdim each program fed to standard input of the next. 369218822Sdim FLAGS As above. 370218822Sdim PNAME The name of the program to report in error messages. 371218822Sdim TEMPBASE A base name to use for temporary files; may be NULL to 372218822Sdim use a random name. 373218822Sdim Returns NULL on error. */ 374218822Sdim 375218822Sdimextern struct pex_obj *pex_init (int flags, const char *pname, 376218822Sdim const char *tempbase); 377218822Sdim 378218822Sdim/* Flags for pex_run. These are bits to be or'ed together. */ 379218822Sdim 380218822Sdim/* Last program in pipeline. Standard output of program goes to 381218822Sdim OUTNAME, or, if OUTNAME is NULL, to standard output of caller. Do 382218822Sdim not set this if you want to call pex_read_output. After this is 383218822Sdim set, pex_run may no longer be called with the same struct 384218822Sdim pex_obj. */ 385218822Sdim#define PEX_LAST 0x1 386218822Sdim 387218822Sdim/* Search for program in executable search path. */ 388218822Sdim#define PEX_SEARCH 0x2 389218822Sdim 390218822Sdim/* OUTNAME is a suffix. */ 391218822Sdim#define PEX_SUFFIX 0x4 392218822Sdim 393218822Sdim/* Send program's standard error to standard output. */ 394218822Sdim#define PEX_STDERR_TO_STDOUT 0x8 395218822Sdim 396218822Sdim/* Input file should be opened in binary mode. This flag is ignored 397218822Sdim on Unix. */ 398218822Sdim#define PEX_BINARY_INPUT 0x10 399218822Sdim 400218822Sdim/* Output file should be opened in binary mode. This flag is ignored 401218822Sdim on Unix. For proper behaviour PEX_BINARY_INPUT and 402218822Sdim PEX_BINARY_OUTPUT have to match appropriately--i.e., a call using 403218822Sdim PEX_BINARY_OUTPUT should be followed by a call using 404218822Sdim PEX_BINARY_INPUT. */ 405218822Sdim#define PEX_BINARY_OUTPUT 0x20 406218822Sdim 407218822Sdim/* Capture stderr to a pipe. The output can be read by 408218822Sdim calling pex_read_err and reading from the returned 409218822Sdim FILE object. This flag may be specified only for 410218822Sdim the last program in a pipeline. 411218822Sdim 412218822Sdim This flag is supported only on Unix and Windows. */ 413218822Sdim#define PEX_STDERR_TO_PIPE 0x40 414218822Sdim 415218822Sdim/* Capture stderr in binary mode. This flag is ignored 416218822Sdim on Unix. */ 417218822Sdim#define PEX_BINARY_ERROR 0x80 418218822Sdim 419218822Sdim 420218822Sdim/* Execute one program. Returns NULL on success. On error returns an 421218822Sdim error string (typically just the name of a system call); the error 422218822Sdim string is statically allocated. 423218822Sdim 424218822Sdim OBJ Returned by pex_init. 425218822Sdim 426218822Sdim FLAGS As above. 427218822Sdim 428218822Sdim EXECUTABLE The program to execute. 429218822Sdim 430218822Sdim ARGV NULL terminated array of arguments to pass to the program. 431218822Sdim 432218822Sdim OUTNAME Sets the output file name as follows: 433218822Sdim 434218822Sdim PEX_SUFFIX set (OUTNAME may not be NULL): 435218822Sdim TEMPBASE parameter to pex_init not NULL: 436218822Sdim Output file name is the concatenation of TEMPBASE 437218822Sdim and OUTNAME. 438218822Sdim TEMPBASE is NULL: 439218822Sdim Output file name is a random file name ending in 440218822Sdim OUTNAME. 441218822Sdim PEX_SUFFIX not set: 442218822Sdim OUTNAME not NULL: 443218822Sdim Output file name is OUTNAME. 444218822Sdim OUTNAME NULL, TEMPBASE not NULL: 445218822Sdim Output file name is randomly chosen using 446218822Sdim TEMPBASE. 447218822Sdim OUTNAME NULL, TEMPBASE NULL: 448218822Sdim Output file name is randomly chosen. 449218822Sdim 450218822Sdim If PEX_LAST is not set, the output file name is the 451218822Sdim name to use for a temporary file holding stdout, if 452218822Sdim any (there will not be a file if PEX_USE_PIPES is set 453218822Sdim and the system supports pipes). If a file is used, it 454218822Sdim will be removed when no longer needed unless 455218822Sdim PEX_SAVE_TEMPS is set. 456218822Sdim 457218822Sdim If PEX_LAST is set, and OUTNAME is not NULL, standard 458218822Sdim output is written to the output file name. The file 459218822Sdim will not be removed. If PEX_LAST and PEX_SUFFIX are 460218822Sdim both set, TEMPBASE may not be NULL. 461218822Sdim 462218822Sdim ERRNAME If not NULL, this is the name of a file to which 463218822Sdim standard error is written. If NULL, standard error of 464218822Sdim the program is standard error of the caller. 465218822Sdim 466218822Sdim ERR On an error return, *ERR is set to an errno value, or 467218822Sdim to 0 if there is no relevant errno. 468218822Sdim*/ 469218822Sdim 470218822Sdimextern const char *pex_run (struct pex_obj *obj, int flags, 471218822Sdim const char *executable, char * const *argv, 472218822Sdim const char *outname, const char *errname, 473218822Sdim int *err); 474218822Sdim 475218822Sdim/* As for pex_run (), but takes an extra parameter to enable the 476218822Sdim environment for the child process to be specified. 477218822Sdim 478218822Sdim ENV The environment for the child process, specified as 479218822Sdim an array of character pointers. Each element of the 480218822Sdim array should point to a string of the form VAR=VALUE, 481218822Sdim with the exception of the last element which must be 482218822Sdim a null pointer. 483218822Sdim*/ 484218822Sdim 485218822Sdimextern const char *pex_run_in_environment (struct pex_obj *obj, int flags, 486218822Sdim const char *executable, 487218822Sdim char * const *argv, 488218822Sdim char * const *env, 489218822Sdim const char *outname, 490218822Sdim const char *errname, int *err); 491218822Sdim 492218822Sdim/* Return a stream for a temporary file to pass to the first program 493218822Sdim in the pipeline as input. The file name is chosen as for pex_run. 494218822Sdim pex_run closes the file automatically; don't close it yourself. */ 495218822Sdim 496218822Sdimextern FILE *pex_input_file (struct pex_obj *obj, int flags, 497218822Sdim const char *in_name); 498218822Sdim 499218822Sdim/* Return a stream for a pipe connected to the standard input of the 500218822Sdim first program in the pipeline. You must have passed 501218822Sdim `PEX_USE_PIPES' to `pex_init'. Close the returned stream 502218822Sdim yourself. */ 503218822Sdim 504218822Sdimextern FILE *pex_input_pipe (struct pex_obj *obj, int binary); 505218822Sdim 506218822Sdim/* Read the standard output of the last program to be executed. 507218822Sdim pex_run can not be called after this. BINARY should be non-zero if 508218822Sdim the file should be opened in binary mode; this is ignored on Unix. 509218822Sdim Returns NULL on error. Don't call fclose on the returned FILE; it 510218822Sdim will be closed by pex_free. */ 511218822Sdim 512218822Sdimextern FILE *pex_read_output (struct pex_obj *, int binary); 513218822Sdim 514218822Sdim/* Read the standard error of the last program to be executed. 515218822Sdim pex_run can not be called after this. BINARY should be non-zero if 516218822Sdim the file should be opened in binary mode; this is ignored on Unix. 517218822Sdim Returns NULL on error. Don't call fclose on the returned FILE; it 518218822Sdim will be closed by pex_free. */ 519218822Sdim 520218822Sdimextern FILE *pex_read_err (struct pex_obj *, int binary); 521218822Sdim 522218822Sdim/* Return exit status of all programs in VECTOR. COUNT indicates the 523218822Sdim size of VECTOR. The status codes in the vector are in the order of 524218822Sdim the calls to pex_run. Returns 0 on error, 1 on success. */ 525218822Sdim 526218822Sdimextern int pex_get_status (struct pex_obj *, int count, int *vector); 527218822Sdim 528218822Sdim/* Return times of all programs in VECTOR. COUNT indicates the size 529218822Sdim of VECTOR. struct pex_time is really just struct timeval, but that 530218822Sdim is not portable to all systems. Returns 0 on error, 1 on 531218822Sdim success. */ 532218822Sdim 533218822Sdimstruct pex_time 534218822Sdim{ 535218822Sdim unsigned long user_seconds; 536218822Sdim unsigned long user_microseconds; 537218822Sdim unsigned long system_seconds; 538218822Sdim unsigned long system_microseconds; 539218822Sdim}; 540218822Sdim 541218822Sdimextern int pex_get_times (struct pex_obj *, int count, 542218822Sdim struct pex_time *vector); 543218822Sdim 544218822Sdim/* Clean up a pex_obj. */ 545218822Sdim 546218822Sdimextern void pex_free (struct pex_obj *); 547218822Sdim 548218822Sdim/* Just execute one program. Return value is as for pex_run. 549218822Sdim FLAGS Combination of PEX_SEARCH and PEX_STDERR_TO_STDOUT. 550218822Sdim EXECUTABLE As for pex_run. 551218822Sdim ARGV As for pex_run. 552218822Sdim PNAME As for pex_init. 553218822Sdim OUTNAME As for pex_run when PEX_LAST is set. 554218822Sdim ERRNAME As for pex_run. 555218822Sdim STATUS Set to exit status on success. 556218822Sdim ERR As for pex_run. 557218822Sdim*/ 558218822Sdim 559218822Sdimextern const char *pex_one (int flags, const char *executable, 560218822Sdim char * const *argv, const char *pname, 561218822Sdim const char *outname, const char *errname, 562218822Sdim int *status, int *err); 563218822Sdim 564218822Sdim/* pexecute and pwait are the old pexecute interface, still here for 565218822Sdim backward compatibility. Don't use these for new code. Instead, 566218822Sdim use pex_init/pex_run/pex_get_status/pex_free, or pex_one. */ 567218822Sdim 56838889Sjdp/* Definitions used by the pexecute routine. */ 56938889Sjdp 57038889Sjdp#define PEXECUTE_FIRST 1 57138889Sjdp#define PEXECUTE_LAST 2 57238889Sjdp#define PEXECUTE_ONE (PEXECUTE_FIRST + PEXECUTE_LAST) 57338889Sjdp#define PEXECUTE_SEARCH 4 57438889Sjdp#define PEXECUTE_VERBOSE 8 57538889Sjdp 57638889Sjdp/* Execute a program. */ 57738889Sjdp 578218822Sdimextern int pexecute (const char *, char * const *, const char *, 579218822Sdim const char *, char **, char **, int); 58038889Sjdp 58138889Sjdp/* Wait for pexecute to finish. */ 58238889Sjdp 583218822Sdimextern int pwait (int, int *, int); 58438889Sjdp 585130561Sobrien#if !HAVE_DECL_ASPRINTF 58660484Sobrien/* Like sprintf but provides a pointer to malloc'd storage, which must 58760484Sobrien be freed by the caller. */ 58860484Sobrien 589218822Sdimextern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2; 590130561Sobrien#endif 59160484Sobrien 592130561Sobrien#if !HAVE_DECL_VASPRINTF 59360484Sobrien/* Like vsprintf but provides a pointer to malloc'd storage, which 59460484Sobrien must be freed by the caller. */ 59560484Sobrien 596218822Sdimextern int vasprintf (char **, const char *, va_list) ATTRIBUTE_PRINTF(2,0); 597130561Sobrien#endif 59860484Sobrien 599218822Sdim#if defined(HAVE_DECL_SNPRINTF) && !HAVE_DECL_SNPRINTF 600218822Sdim/* Like sprintf but prints at most N characters. */ 601218822Sdimextern int snprintf (char *, size_t, const char *, ...) ATTRIBUTE_PRINTF_3; 602218822Sdim#endif 603218822Sdim 604218822Sdim#if defined(HAVE_DECL_VSNPRINTF) && !HAVE_DECL_VSNPRINTF 605218822Sdim/* Like vsprintf but prints at most N characters. */ 606218822Sdimextern int vsnprintf (char *, size_t, const char *, va_list) ATTRIBUTE_PRINTF(3,0); 607218822Sdim#endif 608218822Sdim 609218822Sdim#if defined(HAVE_DECL_STRVERSCMP) && !HAVE_DECL_STRVERSCMP 610218822Sdim/* Compare version strings. */ 611218822Sdimextern int strverscmp (const char *, const char *); 612218822Sdim#endif 613218822Sdim 61477298Sobrien#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) 61577298Sobrien 61689857Sobrien/* Drastically simplified alloca configurator. If we're using GCC, 61789857Sobrien we use __builtin_alloca; otherwise we use the C alloca. The C 61889857Sobrien alloca is always available. You can override GCC by defining 61989857Sobrien USE_C_ALLOCA yourself. The canonical autoconf macro C_ALLOCA is 62089857Sobrien also set/unset as it is often used to indicate whether code needs 62189857Sobrien to call alloca(0). */ 622218822Sdimextern void *C_alloca (size_t) ATTRIBUTE_MALLOC; 62389857Sobrien#undef alloca 62489857Sobrien#if GCC_VERSION >= 2000 && !defined USE_C_ALLOCA 62589857Sobrien# define alloca(x) __builtin_alloca(x) 62689857Sobrien# undef C_ALLOCA 62789857Sobrien# define ASTRDUP(X) \ 62889857Sobrien (__extension__ ({ const char *const libiberty_optr = (X); \ 62989857Sobrien const unsigned long libiberty_len = strlen (libiberty_optr) + 1; \ 630218822Sdim char *const libiberty_nptr = (char *const) alloca (libiberty_len); \ 63189857Sobrien (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len); })) 63289857Sobrien#else 63389857Sobrien# define alloca(x) C_alloca(x) 63489857Sobrien# undef USE_C_ALLOCA 63589857Sobrien# define USE_C_ALLOCA 1 63689857Sobrien# undef C_ALLOCA 63789857Sobrien# define C_ALLOCA 1 63889857Sobrienextern const char *libiberty_optr; 63989857Sobrienextern char *libiberty_nptr; 64089857Sobrienextern unsigned long libiberty_len; 64189857Sobrien# define ASTRDUP(X) \ 64289857Sobrien (libiberty_optr = (X), \ 64389857Sobrien libiberty_len = strlen (libiberty_optr) + 1, \ 644218822Sdim libiberty_nptr = (char *) alloca (libiberty_len), \ 64589857Sobrien (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len)) 64689857Sobrien#endif 64789857Sobrien 64838889Sjdp#ifdef __cplusplus 64938889Sjdp} 65038889Sjdp#endif 65138889Sjdp 65238889Sjdp 65333965Sjdp#endif /* ! defined (LIBIBERTY_H) */ 654