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 299261188Spfg/* APPLE LOCAL begin retune gc params 6124839 */ 300261188Spfgextern unsigned int ncpu_available (void); 301261188Spfg/* APPLE LOCAL end retune gc params 6124839 */ 302261188Spfg 303169695Skan/* Physical memory routines. Return values are in BYTES. */ 304169695Skanextern double physmem_total (void); 305169695Skanextern double physmem_available (void); 306169695Skan 307169695Skan 308169695Skan/* These macros provide a K&R/C89/C++-friendly way of allocating structures 309169695Skan with nice encapsulation. The XDELETE*() macros are technically 310169695Skan superfluous, but provided here for symmetry. Using them consistently 311169695Skan makes it easier to update client code to use different allocators such 312169695Skan as new/delete and new[]/delete[]. */ 313169695Skan 314169695Skan/* Scalar allocators. */ 315169695Skan 316169695Skan#define XNEW(T) ((T *) xmalloc (sizeof (T))) 317169695Skan#define XCNEW(T) ((T *) xcalloc (1, sizeof (T))) 318169695Skan#define XDELETE(P) free ((void*) (P)) 319169695Skan 320169695Skan/* Array allocators. */ 321169695Skan 322169695Skan#define XNEWVEC(T, N) ((T *) xmalloc (sizeof (T) * (N))) 323169695Skan#define XCNEWVEC(T, N) ((T *) xcalloc ((N), sizeof (T))) 324169695Skan#define XRESIZEVEC(T, P, N) ((T *) xrealloc ((void *) (P), sizeof (T) * (N))) 325169695Skan#define XDELETEVEC(P) free ((void*) (P)) 326169695Skan 327169695Skan/* Allocators for variable-sized structures and raw buffers. */ 328169695Skan 329169695Skan#define XNEWVAR(T, S) ((T *) xmalloc ((S))) 330169695Skan#define XCNEWVAR(T, S) ((T *) xcalloc (1, (S))) 331169695Skan#define XRESIZEVAR(T, P, S) ((T *) xrealloc ((P), (S))) 332169695Skan 333169695Skan/* Type-safe obstack allocator. */ 334169695Skan 335169695Skan#define XOBNEW(O, T) ((T *) obstack_alloc ((O), sizeof (T))) 336169695Skan#define XOBFINISH(O, T) ((T) obstack_finish ((O))) 337169695Skan 338169695Skan/* hex character manipulation routines */ 339169695Skan 340169695Skan#define _hex_array_size 256 341169695Skan#define _hex_bad 99 342169695Skanextern const unsigned char _hex_value[_hex_array_size]; 343169695Skanextern void hex_init (void); 344169695Skan#define hex_p(c) (hex_value (c) != _hex_bad) 345169695Skan/* If you change this, note well: Some code relies on side effects in 346169695Skan the argument being performed exactly once. */ 347169695Skan#define hex_value(c) ((unsigned int) _hex_value[(unsigned char) (c)]) 348169695Skan 349169695Skan/* Flags for pex_init. These are bits to be or'ed together. */ 350169695Skan 351169695Skan/* Record subprocess times, if possible. */ 352169695Skan#define PEX_RECORD_TIMES 0x1 353169695Skan 354169695Skan/* Use pipes for communication between processes, if possible. */ 355169695Skan#define PEX_USE_PIPES 0x2 356169695Skan 357169695Skan/* Save files used for communication between processes. */ 358169695Skan#define PEX_SAVE_TEMPS 0x4 359169695Skan 360169695Skan/* Prepare to execute one or more programs, with standard output of 361169695Skan each program fed to standard input of the next. 362169695Skan FLAGS As above. 363169695Skan PNAME The name of the program to report in error messages. 364169695Skan TEMPBASE A base name to use for temporary files; may be NULL to 365169695Skan use a random name. 366169695Skan Returns NULL on error. */ 367169695Skan 368169695Skanextern struct pex_obj *pex_init (int flags, const char *pname, 369169695Skan const char *tempbase); 370169695Skan 371169695Skan/* Flags for pex_run. These are bits to be or'ed together. */ 372169695Skan 373169695Skan/* Last program in pipeline. Standard output of program goes to 374169695Skan OUTNAME, or, if OUTNAME is NULL, to standard output of caller. Do 375169695Skan not set this if you want to call pex_read_output. After this is 376169695Skan set, pex_run may no longer be called with the same struct 377169695Skan pex_obj. */ 378169695Skan#define PEX_LAST 0x1 379169695Skan 380169695Skan/* Search for program in executable search path. */ 381169695Skan#define PEX_SEARCH 0x2 382169695Skan 383169695Skan/* OUTNAME is a suffix. */ 384169695Skan#define PEX_SUFFIX 0x4 385169695Skan 386169695Skan/* Send program's standard error to standard output. */ 387169695Skan#define PEX_STDERR_TO_STDOUT 0x8 388169695Skan 389169695Skan/* Input file should be opened in binary mode. This flag is ignored 390169695Skan on Unix. */ 391169695Skan#define PEX_BINARY_INPUT 0x10 392169695Skan 393169695Skan/* Output file should be opened in binary mode. This flag is ignored 394169695Skan on Unix. For proper behaviour PEX_BINARY_INPUT and 395169695Skan PEX_BINARY_OUTPUT have to match appropriately--i.e., a call using 396169695Skan PEX_BINARY_OUTPUT should be followed by a call using 397169695Skan PEX_BINARY_INPUT. */ 398169695Skan#define PEX_BINARY_OUTPUT 0x20 399169695Skan 400169695Skan/* Execute one program. Returns NULL on success. On error returns an 401169695Skan error string (typically just the name of a system call); the error 402169695Skan string is statically allocated. 403169695Skan 404169695Skan OBJ Returned by pex_init. 405169695Skan 406169695Skan FLAGS As above. 407169695Skan 408169695Skan EXECUTABLE The program to execute. 409169695Skan 410169695Skan ARGV NULL terminated array of arguments to pass to the program. 411169695Skan 412169695Skan OUTNAME Sets the output file name as follows: 413169695Skan 414169695Skan PEX_SUFFIX set (OUTNAME may not be NULL): 415169695Skan TEMPBASE parameter to pex_init not NULL: 416169695Skan Output file name is the concatenation of TEMPBASE 417169695Skan and OUTNAME. 418169695Skan TEMPBASE is NULL: 419169695Skan Output file name is a random file name ending in 420169695Skan OUTNAME. 421169695Skan PEX_SUFFIX not set: 422169695Skan OUTNAME not NULL: 423169695Skan Output file name is OUTNAME. 424169695Skan OUTNAME NULL, TEMPBASE not NULL: 425169695Skan Output file name is randomly chosen using 426169695Skan TEMPBASE. 427169695Skan OUTNAME NULL, TEMPBASE NULL: 428169695Skan Output file name is randomly chosen. 429169695Skan 430169695Skan If PEX_LAST is not set, the output file name is the 431169695Skan name to use for a temporary file holding stdout, if 432169695Skan any (there will not be a file if PEX_USE_PIPES is set 433169695Skan and the system supports pipes). If a file is used, it 434169695Skan will be removed when no longer needed unless 435169695Skan PEX_SAVE_TEMPS is set. 436169695Skan 437169695Skan If PEX_LAST is set, and OUTNAME is not NULL, standard 438169695Skan output is written to the output file name. The file 439169695Skan will not be removed. If PEX_LAST and PEX_SUFFIX are 440169695Skan both set, TEMPBASE may not be NULL. 441169695Skan 442169695Skan ERRNAME If not NULL, this is the name of a file to which 443169695Skan standard error is written. If NULL, standard error of 444169695Skan the program is standard error of the caller. 445169695Skan 446169695Skan ERR On an error return, *ERR is set to an errno value, or 447169695Skan to 0 if there is no relevant errno. 448169695Skan*/ 449169695Skan 450169695Skanextern const char *pex_run (struct pex_obj *obj, int flags, 451169695Skan const char *executable, char * const *argv, 452169695Skan const char *outname, const char *errname, 453169695Skan int *err); 454169695Skan 455169695Skan/* As for pex_run (), but takes an extra parameter to enable the 456169695Skan environment for the child process to be specified. 457169695Skan 458169695Skan ENV The environment for the child process, specified as 459169695Skan an array of character pointers. Each element of the 460169695Skan array should point to a string of the form VAR=VALUE, 461169695Skan with the exception of the last element which must be 462169695Skan a null pointer. 463169695Skan*/ 464169695Skan 465169695Skanextern const char *pex_run_in_environment (struct pex_obj *obj, int flags, 466169695Skan const char *executable, 467169695Skan char * const *argv, 468169695Skan char * const *env, 469169695Skan const char *outname, 470169695Skan const char *errname, int *err); 471169695Skan 472169695Skan/* Return a stream for a temporary file to pass to the first program 473169695Skan in the pipeline as input. The file name is chosen as for pex_run. 474169695Skan pex_run closes the file automatically; don't close it yourself. */ 475169695Skan 476169695Skanextern FILE *pex_input_file (struct pex_obj *obj, int flags, 477169695Skan const char *in_name); 478169695Skan 479169695Skan/* Return a stream for a pipe connected to the standard input of the 480169695Skan first program in the pipeline. You must have passed 481169695Skan `PEX_USE_PIPES' to `pex_init'. Close the returned stream 482169695Skan yourself. */ 483169695Skan 484169695Skanextern FILE *pex_input_pipe (struct pex_obj *obj, int binary); 485169695Skan 486169695Skan/* Read the standard output of the last program to be executed. 487169695Skan pex_run can not be called after this. BINARY should be non-zero if 488169695Skan the file should be opened in binary mode; this is ignored on Unix. 489169695Skan Returns NULL on error. Don't call fclose on the returned FILE; it 490169695Skan will be closed by pex_free. */ 491169695Skan 492169695Skanextern FILE *pex_read_output (struct pex_obj *, int binary); 493169695Skan 494169695Skan/* Return exit status of all programs in VECTOR. COUNT indicates the 495169695Skan size of VECTOR. The status codes in the vector are in the order of 496169695Skan the calls to pex_run. Returns 0 on error, 1 on success. */ 497169695Skan 498169695Skanextern int pex_get_status (struct pex_obj *, int count, int *vector); 499169695Skan 500169695Skan/* Return times of all programs in VECTOR. COUNT indicates the size 501169695Skan of VECTOR. struct pex_time is really just struct timeval, but that 502169695Skan is not portable to all systems. Returns 0 on error, 1 on 503169695Skan success. */ 504169695Skan 505169695Skanstruct pex_time 506169695Skan{ 507169695Skan unsigned long user_seconds; 508169695Skan unsigned long user_microseconds; 509169695Skan unsigned long system_seconds; 510169695Skan unsigned long system_microseconds; 511169695Skan}; 512169695Skan 513169695Skanextern int pex_get_times (struct pex_obj *, int count, 514169695Skan struct pex_time *vector); 515169695Skan 516169695Skan/* Clean up a pex_obj. */ 517169695Skan 518169695Skanextern void pex_free (struct pex_obj *); 519169695Skan 520169695Skan/* Just execute one program. Return value is as for pex_run. 521169695Skan FLAGS Combination of PEX_SEARCH and PEX_STDERR_TO_STDOUT. 522169695Skan EXECUTABLE As for pex_run. 523169695Skan ARGV As for pex_run. 524169695Skan PNAME As for pex_init. 525169695Skan OUTNAME As for pex_run when PEX_LAST is set. 526169695Skan ERRNAME As for pex_run. 527169695Skan STATUS Set to exit status on success. 528169695Skan ERR As for pex_run. 529169695Skan*/ 530169695Skan 531169695Skanextern const char *pex_one (int flags, const char *executable, 532169695Skan char * const *argv, const char *pname, 533169695Skan const char *outname, const char *errname, 534169695Skan int *status, int *err); 535169695Skan 536169695Skan/* pexecute and pwait are the old pexecute interface, still here for 537169695Skan backward compatibility. Don't use these for new code. Instead, 538169695Skan use pex_init/pex_run/pex_get_status/pex_free, or pex_one. */ 539169695Skan 540169695Skan/* Definitions used by the pexecute routine. */ 541169695Skan 542169695Skan#define PEXECUTE_FIRST 1 543169695Skan#define PEXECUTE_LAST 2 544169695Skan#define PEXECUTE_ONE (PEXECUTE_FIRST + PEXECUTE_LAST) 545169695Skan#define PEXECUTE_SEARCH 4 546169695Skan#define PEXECUTE_VERBOSE 8 547169695Skan 548169695Skan/* Execute a program. */ 549169695Skan 550169695Skanextern int pexecute (const char *, char * const *, const char *, 551169695Skan const char *, char **, char **, int); 552169695Skan 553169695Skan/* Wait for pexecute to finish. */ 554169695Skan 555169695Skanextern int pwait (int, int *, int); 556169695Skan 557169695Skan#if !HAVE_DECL_ASPRINTF 558169695Skan/* Like sprintf but provides a pointer to malloc'd storage, which must 559169695Skan be freed by the caller. */ 560169695Skan 561169695Skanextern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2; 562169695Skan#endif 563169695Skan 564169695Skan#if !HAVE_DECL_VASPRINTF 565169695Skan/* Like vsprintf but provides a pointer to malloc'd storage, which 566169695Skan must be freed by the caller. */ 567169695Skan 568169695Skanextern int vasprintf (char **, const char *, va_list) ATTRIBUTE_PRINTF(2,0); 569169695Skan#endif 570169695Skan 571169695Skan#if defined(HAVE_DECL_SNPRINTF) && !HAVE_DECL_SNPRINTF 572169695Skan/* Like sprintf but prints at most N characters. */ 573169695Skanextern int snprintf (char *, size_t, const char *, ...) ATTRIBUTE_PRINTF_3; 574169695Skan#endif 575169695Skan 576169695Skan#if defined(HAVE_DECL_VSNPRINTF) && !HAVE_DECL_VSNPRINTF 577169695Skan/* Like vsprintf but prints at most N characters. */ 578169695Skanextern int vsnprintf (char *, size_t, const char *, va_list) ATTRIBUTE_PRINTF(3,0); 579169695Skan#endif 580169695Skan 581169695Skan#if defined(HAVE_DECL_STRVERSCMP) && !HAVE_DECL_STRVERSCMP 582169695Skan/* Compare version strings. */ 583169695Skanextern int strverscmp (const char *, const char *); 584169695Skan#endif 585169695Skan 586169695Skan#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) 587169695Skan 588169695Skan/* Drastically simplified alloca configurator. If we're using GCC, 589169695Skan we use __builtin_alloca; otherwise we use the C alloca. The C 590169695Skan alloca is always available. You can override GCC by defining 591169695Skan USE_C_ALLOCA yourself. The canonical autoconf macro C_ALLOCA is 592169695Skan also set/unset as it is often used to indicate whether code needs 593169695Skan to call alloca(0). */ 594169695Skanextern void *C_alloca (size_t) ATTRIBUTE_MALLOC; 595169695Skan#undef alloca 596169695Skan#if GCC_VERSION >= 2000 && !defined USE_C_ALLOCA 597169695Skan# define alloca(x) __builtin_alloca(x) 598169695Skan# undef C_ALLOCA 599169695Skan# define ASTRDUP(X) \ 600169695Skan (__extension__ ({ const char *const libiberty_optr = (X); \ 601169695Skan const unsigned long libiberty_len = strlen (libiberty_optr) + 1; \ 602169695Skan char *const libiberty_nptr = (char *const) alloca (libiberty_len); \ 603169695Skan (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len); })) 604169695Skan#else 605169695Skan# define alloca(x) C_alloca(x) 606169695Skan# undef USE_C_ALLOCA 607169695Skan# define USE_C_ALLOCA 1 608169695Skan# undef C_ALLOCA 609169695Skan# define C_ALLOCA 1 610169695Skanextern const char *libiberty_optr; 611169695Skanextern char *libiberty_nptr; 612169695Skanextern unsigned long libiberty_len; 613169695Skan# define ASTRDUP(X) \ 614169695Skan (libiberty_optr = (X), \ 615169695Skan libiberty_len = strlen (libiberty_optr) + 1, \ 616169695Skan libiberty_nptr = (char *) alloca (libiberty_len), \ 617169695Skan (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len)) 618169695Skan#endif 619169695Skan 620169695Skan#ifdef __cplusplus 621169695Skan} 622169695Skan#endif 623169695Skan 624169695Skan 625169695Skan#endif /* ! defined (LIBIBERTY_H) */ 626