1*404b540aSrobert /* Function declarations for libiberty. 2*404b540aSrobert 3*404b540aSrobert Copyright 2001, 2002, 2005 Free Software Foundation, Inc. 4*404b540aSrobert 5*404b540aSrobert Note - certain prototypes declared in this header file are for 6*404b540aSrobert functions whoes implementation copyright does not belong to the 7*404b540aSrobert FSF. Those prototypes are present in this file for reference 8*404b540aSrobert purposes only and their presence in this file should not construed 9*404b540aSrobert as an indication of ownership by the FSF of the implementation of 10*404b540aSrobert those functions in any way or form whatsoever. 11*404b540aSrobert 12*404b540aSrobert This program is free software; you can redistribute it and/or modify 13*404b540aSrobert it under the terms of the GNU General Public License as published by 14*404b540aSrobert the Free Software Foundation; either version 2, or (at your option) 15*404b540aSrobert any later version. 16*404b540aSrobert 17*404b540aSrobert This program is distributed in the hope that it will be useful, 18*404b540aSrobert but WITHOUT ANY WARRANTY; without even the implied warranty of 19*404b540aSrobert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20*404b540aSrobert GNU General Public License for more details. 21*404b540aSrobert 22*404b540aSrobert You should have received a copy of the GNU General Public License 23*404b540aSrobert along with this program; if not, write to the Free Software 24*404b540aSrobert Foundation, Inc., 51 Franklin Street - Fifth Floor, 25*404b540aSrobert Boston, MA 02110-1301, USA. 26*404b540aSrobert 27*404b540aSrobert Written by Cygnus Support, 1994. 28*404b540aSrobert 29*404b540aSrobert The libiberty library provides a number of functions which are 30*404b540aSrobert missing on some operating systems. We do not declare those here, 31*404b540aSrobert to avoid conflicts with the system header files on operating 32*404b540aSrobert systems that do support those functions. In this file we only 33*404b540aSrobert declare those functions which are specific to libiberty. */ 34*404b540aSrobert 35*404b540aSrobert #ifndef LIBIBERTY_H 36*404b540aSrobert #define LIBIBERTY_H 37*404b540aSrobert 38*404b540aSrobert #ifdef __cplusplus 39*404b540aSrobert extern "C" { 40*404b540aSrobert #endif 41*404b540aSrobert 42*404b540aSrobert #include "ansidecl.h" 43*404b540aSrobert 44*404b540aSrobert /* Get a definition for size_t. */ 45*404b540aSrobert #include <stddef.h> 46*404b540aSrobert /* Get a definition for va_list. */ 47*404b540aSrobert #include <stdarg.h> 48*404b540aSrobert 49*404b540aSrobert #include <stdio.h> 50*404b540aSrobert 51*404b540aSrobert /* If the OS supports it, ensure that the supplied stream is setup to 52*404b540aSrobert avoid any multi-threaded locking. Otherwise leave the FILE pointer 53*404b540aSrobert unchanged. If the stream is NULL do nothing. */ 54*404b540aSrobert 55*404b540aSrobert extern void unlock_stream (FILE *); 56*404b540aSrobert 57*404b540aSrobert /* If the OS supports it, ensure that the standard I/O streams, stdin, 58*404b540aSrobert stdout and stderr are setup to avoid any multi-threaded locking. 59*404b540aSrobert Otherwise do nothing. */ 60*404b540aSrobert 61*404b540aSrobert extern void unlock_std_streams (void); 62*404b540aSrobert 63*404b540aSrobert /* Open and return a FILE pointer. If the OS supports it, ensure that 64*404b540aSrobert the stream is setup to avoid any multi-threaded locking. Otherwise 65*404b540aSrobert return the FILE pointer unchanged. */ 66*404b540aSrobert 67*404b540aSrobert extern FILE *fopen_unlocked (const char *, const char *); 68*404b540aSrobert extern FILE *fdopen_unlocked (int, const char *); 69*404b540aSrobert extern FILE *freopen_unlocked (const char *, const char *, FILE *); 70*404b540aSrobert 71*404b540aSrobert /* Build an argument vector from a string. Allocates memory using 72*404b540aSrobert malloc. Use freeargv to free the vector. */ 73*404b540aSrobert 74*404b540aSrobert extern char **buildargv (const char *) ATTRIBUTE_MALLOC; 75*404b540aSrobert 76*404b540aSrobert /* Free a vector returned by buildargv. */ 77*404b540aSrobert 78*404b540aSrobert extern void freeargv (char **); 79*404b540aSrobert 80*404b540aSrobert /* Duplicate an argument vector. Allocates memory using malloc. Use 81*404b540aSrobert freeargv to free the vector. */ 82*404b540aSrobert 83*404b540aSrobert extern char **dupargv (char **) ATTRIBUTE_MALLOC; 84*404b540aSrobert 85*404b540aSrobert /* Expand "@file" arguments in argv. */ 86*404b540aSrobert 87*404b540aSrobert extern void expandargv PARAMS ((int *, char ***)); 88*404b540aSrobert 89*404b540aSrobert /* Return the last component of a path name. Note that we can't use a 90*404b540aSrobert prototype here because the parameter is declared inconsistently 91*404b540aSrobert across different systems, sometimes as "char *" and sometimes as 92*404b540aSrobert "const char *" */ 93*404b540aSrobert 94*404b540aSrobert /* HAVE_DECL_* is a three-state macro: undefined, 0 or 1. If it is 95*404b540aSrobert undefined, we haven't run the autoconf check so provide the 96*404b540aSrobert declaration without arguments. If it is 0, we checked and failed 97*404b540aSrobert to find the declaration so provide a fully prototyped one. If it 98*404b540aSrobert is 1, we found it so don't provide any declaration at all. */ 99*404b540aSrobert #if !HAVE_DECL_BASENAME 100*404b540aSrobert #if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || defined (__MINGW32__) || defined (HAVE_DECL_BASENAME) 101*404b540aSrobert extern char *basename (const char *); 102*404b540aSrobert #else 103*404b540aSrobert /* Do not allow basename to be used if there is no prototype seen. We 104*404b540aSrobert either need to use the above prototype or have one from 105*404b540aSrobert autoconf which would result in HAVE_DECL_BASENAME being set. */ 106*404b540aSrobert #define basename basename_cannot_be_used_without_a_prototype 107*404b540aSrobert #endif 108*404b540aSrobert #endif 109*404b540aSrobert 110*404b540aSrobert /* A well-defined basename () that is always compiled in. */ 111*404b540aSrobert 112*404b540aSrobert extern const char *lbasename (const char *); 113*404b540aSrobert 114*404b540aSrobert /* A well-defined realpath () that is always compiled in. */ 115*404b540aSrobert 116*404b540aSrobert extern char *lrealpath (const char *); 117*404b540aSrobert 118*404b540aSrobert /* Concatenate an arbitrary number of strings. You must pass NULL as 119*404b540aSrobert the last argument of this function, to terminate the list of 120*404b540aSrobert strings. Allocates memory using xmalloc. */ 121*404b540aSrobert 122*404b540aSrobert extern char *concat (const char *, ...) ATTRIBUTE_MALLOC ATTRIBUTE_SENTINEL; 123*404b540aSrobert 124*404b540aSrobert /* Concatenate an arbitrary number of strings. You must pass NULL as 125*404b540aSrobert the last argument of this function, to terminate the list of 126*404b540aSrobert strings. Allocates memory using xmalloc. The first argument is 127*404b540aSrobert not one of the strings to be concatenated, but if not NULL is a 128*404b540aSrobert pointer to be freed after the new string is created, similar to the 129*404b540aSrobert way xrealloc works. */ 130*404b540aSrobert 131*404b540aSrobert extern char *reconcat (char *, const char *, ...) ATTRIBUTE_MALLOC ATTRIBUTE_SENTINEL; 132*404b540aSrobert 133*404b540aSrobert /* Determine the length of concatenating an arbitrary number of 134*404b540aSrobert strings. You must pass NULL as the last argument of this function, 135*404b540aSrobert to terminate the list of strings. */ 136*404b540aSrobert 137*404b540aSrobert extern unsigned long concat_length (const char *, ...) ATTRIBUTE_SENTINEL; 138*404b540aSrobert 139*404b540aSrobert /* Concatenate an arbitrary number of strings into a SUPPLIED area of 140*404b540aSrobert memory. You must pass NULL as the last argument of this function, 141*404b540aSrobert to terminate the list of strings. The supplied memory is assumed 142*404b540aSrobert to be large enough. */ 143*404b540aSrobert 144*404b540aSrobert extern char *concat_copy (char *, const char *, ...) ATTRIBUTE_SENTINEL; 145*404b540aSrobert 146*404b540aSrobert /* Concatenate an arbitrary number of strings into a GLOBAL area of 147*404b540aSrobert memory. You must pass NULL as the last argument of this function, 148*404b540aSrobert to terminate the list of strings. The supplied memory is assumed 149*404b540aSrobert to be large enough. */ 150*404b540aSrobert 151*404b540aSrobert extern char *concat_copy2 (const char *, ...) ATTRIBUTE_SENTINEL; 152*404b540aSrobert 153*404b540aSrobert /* This is the global area used by concat_copy2. */ 154*404b540aSrobert 155*404b540aSrobert extern char *libiberty_concat_ptr; 156*404b540aSrobert 157*404b540aSrobert /* Concatenate an arbitrary number of strings. You must pass NULL as 158*404b540aSrobert the last argument of this function, to terminate the list of 159*404b540aSrobert strings. Allocates memory using alloca. The arguments are 160*404b540aSrobert evaluated twice! */ 161*404b540aSrobert #define ACONCAT(ACONCAT_PARAMS) \ 162*404b540aSrobert (libiberty_concat_ptr = (char *) alloca (concat_length ACONCAT_PARAMS + 1), \ 163*404b540aSrobert concat_copy2 ACONCAT_PARAMS) 164*404b540aSrobert 165*404b540aSrobert /* Check whether two file descriptors refer to the same file. */ 166*404b540aSrobert 167*404b540aSrobert extern int fdmatch (int fd1, int fd2); 168*404b540aSrobert 169*404b540aSrobert /* Return the position of the first bit set in the argument. */ 170*404b540aSrobert /* Prototypes vary from system to system, so we only provide a 171*404b540aSrobert prototype on systems where we know that we need it. */ 172*404b540aSrobert #if defined (HAVE_DECL_FFS) && !HAVE_DECL_FFS 173*404b540aSrobert extern int ffs(int); 174*404b540aSrobert #endif 175*404b540aSrobert 176*404b540aSrobert /* Get the working directory. The result is cached, so don't call 177*404b540aSrobert chdir() between calls to getpwd(). */ 178*404b540aSrobert 179*404b540aSrobert extern char * getpwd (void); 180*404b540aSrobert 181*404b540aSrobert /* Get the current time. */ 182*404b540aSrobert /* Prototypes vary from system to system, so we only provide a 183*404b540aSrobert prototype on systems where we know that we need it. */ 184*404b540aSrobert #ifdef __MINGW32__ 185*404b540aSrobert /* Forward declaration to avoid #include <sys/time.h>. */ 186*404b540aSrobert struct timeval; 187*404b540aSrobert extern int gettimeofday (struct timeval *, void *); 188*404b540aSrobert #endif 189*404b540aSrobert 190*404b540aSrobert /* Get the amount of time the process has run, in microseconds. */ 191*404b540aSrobert 192*404b540aSrobert extern long get_run_time (void); 193*404b540aSrobert 194*404b540aSrobert /* Generate a relocated path to some installation directory. Allocates 195*404b540aSrobert return value using malloc. */ 196*404b540aSrobert 197*404b540aSrobert extern char *make_relative_prefix (const char *, const char *, 198*404b540aSrobert const char *) ATTRIBUTE_MALLOC; 199*404b540aSrobert 200*404b540aSrobert /* Choose a temporary directory to use for scratch files. */ 201*404b540aSrobert 202*404b540aSrobert extern char *choose_temp_base (void) ATTRIBUTE_MALLOC; 203*404b540aSrobert 204*404b540aSrobert /* Return a temporary file name or NULL if unable to create one. */ 205*404b540aSrobert 206*404b540aSrobert extern char *make_temp_file (const char *) ATTRIBUTE_MALLOC; 207*404b540aSrobert 208*404b540aSrobert /* Remove a link to a file unless it is special. */ 209*404b540aSrobert 210*404b540aSrobert extern int unlink_if_ordinary (const char *); 211*404b540aSrobert 212*404b540aSrobert /* Allocate memory filled with spaces. Allocates using malloc. */ 213*404b540aSrobert 214*404b540aSrobert extern const char *spaces (int count); 215*404b540aSrobert 216*404b540aSrobert /* Return the maximum error number for which strerror will return a 217*404b540aSrobert string. */ 218*404b540aSrobert 219*404b540aSrobert extern int errno_max (void); 220*404b540aSrobert 221*404b540aSrobert /* Return the name of an errno value (e.g., strerrno (EINVAL) returns 222*404b540aSrobert "EINVAL"). */ 223*404b540aSrobert 224*404b540aSrobert extern const char *strerrno (int); 225*404b540aSrobert 226*404b540aSrobert /* Given the name of an errno value, return the value. */ 227*404b540aSrobert 228*404b540aSrobert extern int strtoerrno (const char *); 229*404b540aSrobert 230*404b540aSrobert /* ANSI's strerror(), but more robust. */ 231*404b540aSrobert 232*404b540aSrobert extern char *xstrerror (int); 233*404b540aSrobert 234*404b540aSrobert /* Return the maximum signal number for which strsignal will return a 235*404b540aSrobert string. */ 236*404b540aSrobert 237*404b540aSrobert extern int signo_max (void); 238*404b540aSrobert 239*404b540aSrobert /* Return a signal message string for a signal number 240*404b540aSrobert (e.g., strsignal (SIGHUP) returns something like "Hangup"). */ 241*404b540aSrobert /* This is commented out as it can conflict with one in system headers. 242*404b540aSrobert We still document its existence though. */ 243*404b540aSrobert 244*404b540aSrobert /*extern const char *strsignal (int);*/ 245*404b540aSrobert 246*404b540aSrobert /* Return the name of a signal number (e.g., strsigno (SIGHUP) returns 247*404b540aSrobert "SIGHUP"). */ 248*404b540aSrobert 249*404b540aSrobert extern const char *strsigno (int); 250*404b540aSrobert 251*404b540aSrobert /* Given the name of a signal, return its number. */ 252*404b540aSrobert 253*404b540aSrobert extern int strtosigno (const char *); 254*404b540aSrobert 255*404b540aSrobert /* Register a function to be run by xexit. Returns 0 on success. */ 256*404b540aSrobert 257*404b540aSrobert extern int xatexit (void (*fn) (void)); 258*404b540aSrobert 259*404b540aSrobert /* Exit, calling all the functions registered with xatexit. */ 260*404b540aSrobert 261*404b540aSrobert extern void xexit (int status) ATTRIBUTE_NORETURN; 262*404b540aSrobert 263*404b540aSrobert /* Set the program name used by xmalloc. */ 264*404b540aSrobert 265*404b540aSrobert extern void xmalloc_set_program_name (const char *); 266*404b540aSrobert 267*404b540aSrobert /* Report an allocation failure. */ 268*404b540aSrobert extern void xmalloc_failed (size_t) ATTRIBUTE_NORETURN; 269*404b540aSrobert 270*404b540aSrobert /* Allocate memory without fail. If malloc fails, this will print a 271*404b540aSrobert message to stderr (using the name set by xmalloc_set_program_name, 272*404b540aSrobert if any) and then call xexit. */ 273*404b540aSrobert 274*404b540aSrobert extern void *xmalloc (size_t) ATTRIBUTE_MALLOC; 275*404b540aSrobert 276*404b540aSrobert /* Reallocate memory without fail. This works like xmalloc. Note, 277*404b540aSrobert realloc type functions are not suitable for attribute malloc since 278*404b540aSrobert they may return the same address across multiple calls. */ 279*404b540aSrobert 280*404b540aSrobert extern void *xrealloc (void *, size_t); 281*404b540aSrobert 282*404b540aSrobert /* Allocate memory without fail and set it to zero. This works like 283*404b540aSrobert xmalloc. */ 284*404b540aSrobert 285*404b540aSrobert extern void *xcalloc (size_t, size_t) ATTRIBUTE_MALLOC; 286*404b540aSrobert 287*404b540aSrobert /* Copy a string into a memory buffer without fail. */ 288*404b540aSrobert 289*404b540aSrobert extern char *xstrdup (const char *) ATTRIBUTE_MALLOC; 290*404b540aSrobert 291*404b540aSrobert /* Copy at most N characters from string into a buffer without fail. */ 292*404b540aSrobert 293*404b540aSrobert extern char *xstrndup (const char *, size_t) ATTRIBUTE_MALLOC; 294*404b540aSrobert 295*404b540aSrobert /* Copy an existing memory buffer to a new memory buffer without fail. */ 296*404b540aSrobert 297*404b540aSrobert extern void *xmemdup (const void *, size_t, size_t) ATTRIBUTE_MALLOC; 298*404b540aSrobert 299*404b540aSrobert /* Physical memory routines. Return values are in BYTES. */ 300*404b540aSrobert extern double physmem_total (void); 301*404b540aSrobert extern double physmem_available (void); 302*404b540aSrobert 303*404b540aSrobert 304*404b540aSrobert /* These macros provide a K&R/C89/C++-friendly way of allocating structures 305*404b540aSrobert with nice encapsulation. The XDELETE*() macros are technically 306*404b540aSrobert superfluous, but provided here for symmetry. Using them consistently 307*404b540aSrobert makes it easier to update client code to use different allocators such 308*404b540aSrobert as new/delete and new[]/delete[]. */ 309*404b540aSrobert 310*404b540aSrobert /* Scalar allocators. */ 311*404b540aSrobert 312*404b540aSrobert #define XNEW(T) ((T *) xmalloc (sizeof (T))) 313*404b540aSrobert #define XCNEW(T) ((T *) xcalloc (1, sizeof (T))) 314*404b540aSrobert #define XDELETE(P) free ((void*) (P)) 315*404b540aSrobert 316*404b540aSrobert /* Array allocators. */ 317*404b540aSrobert 318*404b540aSrobert #define XNEWVEC(T, N) ((T *) xmalloc (sizeof (T) * (N))) 319*404b540aSrobert #define XCNEWVEC(T, N) ((T *) xcalloc ((N), sizeof (T))) 320*404b540aSrobert #define XRESIZEVEC(T, P, N) ((T *) xrealloc ((void *) (P), sizeof (T) * (N))) 321*404b540aSrobert #define XDELETEVEC(P) free ((void*) (P)) 322*404b540aSrobert 323*404b540aSrobert /* Allocators for variable-sized structures and raw buffers. */ 324*404b540aSrobert 325*404b540aSrobert #define XNEWVAR(T, S) ((T *) xmalloc ((S))) 326*404b540aSrobert #define XCNEWVAR(T, S) ((T *) xcalloc (1, (S))) 327*404b540aSrobert #define XRESIZEVAR(T, P, S) ((T *) xrealloc ((P), (S))) 328*404b540aSrobert 329*404b540aSrobert /* Type-safe obstack allocator. */ 330*404b540aSrobert 331*404b540aSrobert #define XOBNEW(O, T) ((T *) obstack_alloc ((O), sizeof (T))) 332*404b540aSrobert #define XOBFINISH(O, T) ((T) obstack_finish ((O))) 333*404b540aSrobert 334*404b540aSrobert /* hex character manipulation routines */ 335*404b540aSrobert 336*404b540aSrobert #define _hex_array_size 256 337*404b540aSrobert #define _hex_bad 99 338*404b540aSrobert extern const unsigned char _hex_value[_hex_array_size]; 339*404b540aSrobert extern void hex_init (void); 340*404b540aSrobert #define hex_p(c) (hex_value (c) != _hex_bad) 341*404b540aSrobert /* If you change this, note well: Some code relies on side effects in 342*404b540aSrobert the argument being performed exactly once. */ 343*404b540aSrobert #define hex_value(c) ((unsigned int) _hex_value[(unsigned char) (c)]) 344*404b540aSrobert 345*404b540aSrobert /* Flags for pex_init. These are bits to be or'ed together. */ 346*404b540aSrobert 347*404b540aSrobert /* Record subprocess times, if possible. */ 348*404b540aSrobert #define PEX_RECORD_TIMES 0x1 349*404b540aSrobert 350*404b540aSrobert /* Use pipes for communication between processes, if possible. */ 351*404b540aSrobert #define PEX_USE_PIPES 0x2 352*404b540aSrobert 353*404b540aSrobert /* Save files used for communication between processes. */ 354*404b540aSrobert #define PEX_SAVE_TEMPS 0x4 355*404b540aSrobert 356*404b540aSrobert /* Prepare to execute one or more programs, with standard output of 357*404b540aSrobert each program fed to standard input of the next. 358*404b540aSrobert FLAGS As above. 359*404b540aSrobert PNAME The name of the program to report in error messages. 360*404b540aSrobert TEMPBASE A base name to use for temporary files; may be NULL to 361*404b540aSrobert use a random name. 362*404b540aSrobert Returns NULL on error. */ 363*404b540aSrobert 364*404b540aSrobert extern struct pex_obj *pex_init (int flags, const char *pname, 365*404b540aSrobert const char *tempbase); 366*404b540aSrobert 367*404b540aSrobert /* Flags for pex_run. These are bits to be or'ed together. */ 368*404b540aSrobert 369*404b540aSrobert /* Last program in pipeline. Standard output of program goes to 370*404b540aSrobert OUTNAME, or, if OUTNAME is NULL, to standard output of caller. Do 371*404b540aSrobert not set this if you want to call pex_read_output. After this is 372*404b540aSrobert set, pex_run may no longer be called with the same struct 373*404b540aSrobert pex_obj. */ 374*404b540aSrobert #define PEX_LAST 0x1 375*404b540aSrobert 376*404b540aSrobert /* Search for program in executable search path. */ 377*404b540aSrobert #define PEX_SEARCH 0x2 378*404b540aSrobert 379*404b540aSrobert /* OUTNAME is a suffix. */ 380*404b540aSrobert #define PEX_SUFFIX 0x4 381*404b540aSrobert 382*404b540aSrobert /* Send program's standard error to standard output. */ 383*404b540aSrobert #define PEX_STDERR_TO_STDOUT 0x8 384*404b540aSrobert 385*404b540aSrobert /* Input file should be opened in binary mode. This flag is ignored 386*404b540aSrobert on Unix. */ 387*404b540aSrobert #define PEX_BINARY_INPUT 0x10 388*404b540aSrobert 389*404b540aSrobert /* Output file should be opened in binary mode. This flag is ignored 390*404b540aSrobert on Unix. For proper behaviour PEX_BINARY_INPUT and 391*404b540aSrobert PEX_BINARY_OUTPUT have to match appropriately--i.e., a call using 392*404b540aSrobert PEX_BINARY_OUTPUT should be followed by a call using 393*404b540aSrobert PEX_BINARY_INPUT. */ 394*404b540aSrobert #define PEX_BINARY_OUTPUT 0x20 395*404b540aSrobert 396*404b540aSrobert /* Execute one program. Returns NULL on success. On error returns an 397*404b540aSrobert error string (typically just the name of a system call); the error 398*404b540aSrobert string is statically allocated. 399*404b540aSrobert 400*404b540aSrobert OBJ Returned by pex_init. 401*404b540aSrobert 402*404b540aSrobert FLAGS As above. 403*404b540aSrobert 404*404b540aSrobert EXECUTABLE The program to execute. 405*404b540aSrobert 406*404b540aSrobert ARGV NULL terminated array of arguments to pass to the program. 407*404b540aSrobert 408*404b540aSrobert OUTNAME Sets the output file name as follows: 409*404b540aSrobert 410*404b540aSrobert PEX_SUFFIX set (OUTNAME may not be NULL): 411*404b540aSrobert TEMPBASE parameter to pex_init not NULL: 412*404b540aSrobert Output file name is the concatenation of TEMPBASE 413*404b540aSrobert and OUTNAME. 414*404b540aSrobert TEMPBASE is NULL: 415*404b540aSrobert Output file name is a random file name ending in 416*404b540aSrobert OUTNAME. 417*404b540aSrobert PEX_SUFFIX not set: 418*404b540aSrobert OUTNAME not NULL: 419*404b540aSrobert Output file name is OUTNAME. 420*404b540aSrobert OUTNAME NULL, TEMPBASE not NULL: 421*404b540aSrobert Output file name is randomly chosen using 422*404b540aSrobert TEMPBASE. 423*404b540aSrobert OUTNAME NULL, TEMPBASE NULL: 424*404b540aSrobert Output file name is randomly chosen. 425*404b540aSrobert 426*404b540aSrobert If PEX_LAST is not set, the output file name is the 427*404b540aSrobert name to use for a temporary file holding stdout, if 428*404b540aSrobert any (there will not be a file if PEX_USE_PIPES is set 429*404b540aSrobert and the system supports pipes). If a file is used, it 430*404b540aSrobert will be removed when no longer needed unless 431*404b540aSrobert PEX_SAVE_TEMPS is set. 432*404b540aSrobert 433*404b540aSrobert If PEX_LAST is set, and OUTNAME is not NULL, standard 434*404b540aSrobert output is written to the output file name. The file 435*404b540aSrobert will not be removed. If PEX_LAST and PEX_SUFFIX are 436*404b540aSrobert both set, TEMPBASE may not be NULL. 437*404b540aSrobert 438*404b540aSrobert ERRNAME If not NULL, this is the name of a file to which 439*404b540aSrobert standard error is written. If NULL, standard error of 440*404b540aSrobert the program is standard error of the caller. 441*404b540aSrobert 442*404b540aSrobert ERR On an error return, *ERR is set to an errno value, or 443*404b540aSrobert to 0 if there is no relevant errno. 444*404b540aSrobert */ 445*404b540aSrobert 446*404b540aSrobert extern const char *pex_run (struct pex_obj *obj, int flags, 447*404b540aSrobert const char *executable, char * const *argv, 448*404b540aSrobert const char *outname, const char *errname, 449*404b540aSrobert int *err); 450*404b540aSrobert 451*404b540aSrobert /* As for pex_run (), but takes an extra parameter to enable the 452*404b540aSrobert environment for the child process to be specified. 453*404b540aSrobert 454*404b540aSrobert ENV The environment for the child process, specified as 455*404b540aSrobert an array of character pointers. Each element of the 456*404b540aSrobert array should point to a string of the form VAR=VALUE, 457*404b540aSrobert with the exception of the last element which must be 458*404b540aSrobert a null pointer. 459*404b540aSrobert */ 460*404b540aSrobert 461*404b540aSrobert extern const char *pex_run_in_environment (struct pex_obj *obj, int flags, 462*404b540aSrobert const char *executable, 463*404b540aSrobert char * const *argv, 464*404b540aSrobert char * const *env, 465*404b540aSrobert const char *outname, 466*404b540aSrobert const char *errname, int *err); 467*404b540aSrobert 468*404b540aSrobert /* Return a stream for a temporary file to pass to the first program 469*404b540aSrobert in the pipeline as input. The file name is chosen as for pex_run. 470*404b540aSrobert pex_run closes the file automatically; don't close it yourself. */ 471*404b540aSrobert 472*404b540aSrobert extern FILE *pex_input_file (struct pex_obj *obj, int flags, 473*404b540aSrobert const char *in_name); 474*404b540aSrobert 475*404b540aSrobert /* Return a stream for a pipe connected to the standard input of the 476*404b540aSrobert first program in the pipeline. You must have passed 477*404b540aSrobert `PEX_USE_PIPES' to `pex_init'. Close the returned stream 478*404b540aSrobert yourself. */ 479*404b540aSrobert 480*404b540aSrobert extern FILE *pex_input_pipe (struct pex_obj *obj, int binary); 481*404b540aSrobert 482*404b540aSrobert /* Read the standard output of the last program to be executed. 483*404b540aSrobert pex_run can not be called after this. BINARY should be non-zero if 484*404b540aSrobert the file should be opened in binary mode; this is ignored on Unix. 485*404b540aSrobert Returns NULL on error. Don't call fclose on the returned FILE; it 486*404b540aSrobert will be closed by pex_free. */ 487*404b540aSrobert 488*404b540aSrobert extern FILE *pex_read_output (struct pex_obj *, int binary); 489*404b540aSrobert 490*404b540aSrobert /* Return exit status of all programs in VECTOR. COUNT indicates the 491*404b540aSrobert size of VECTOR. The status codes in the vector are in the order of 492*404b540aSrobert the calls to pex_run. Returns 0 on error, 1 on success. */ 493*404b540aSrobert 494*404b540aSrobert extern int pex_get_status (struct pex_obj *, int count, int *vector); 495*404b540aSrobert 496*404b540aSrobert /* Return times of all programs in VECTOR. COUNT indicates the size 497*404b540aSrobert of VECTOR. struct pex_time is really just struct timeval, but that 498*404b540aSrobert is not portable to all systems. Returns 0 on error, 1 on 499*404b540aSrobert success. */ 500*404b540aSrobert 501*404b540aSrobert struct pex_time 502*404b540aSrobert { 503*404b540aSrobert unsigned long user_seconds; 504*404b540aSrobert unsigned long user_microseconds; 505*404b540aSrobert unsigned long system_seconds; 506*404b540aSrobert unsigned long system_microseconds; 507*404b540aSrobert }; 508*404b540aSrobert 509*404b540aSrobert extern int pex_get_times (struct pex_obj *, int count, 510*404b540aSrobert struct pex_time *vector); 511*404b540aSrobert 512*404b540aSrobert /* Clean up a pex_obj. */ 513*404b540aSrobert 514*404b540aSrobert extern void pex_free (struct pex_obj *); 515*404b540aSrobert 516*404b540aSrobert /* Just execute one program. Return value is as for pex_run. 517*404b540aSrobert FLAGS Combination of PEX_SEARCH and PEX_STDERR_TO_STDOUT. 518*404b540aSrobert EXECUTABLE As for pex_run. 519*404b540aSrobert ARGV As for pex_run. 520*404b540aSrobert PNAME As for pex_init. 521*404b540aSrobert OUTNAME As for pex_run when PEX_LAST is set. 522*404b540aSrobert ERRNAME As for pex_run. 523*404b540aSrobert STATUS Set to exit status on success. 524*404b540aSrobert ERR As for pex_run. 525*404b540aSrobert */ 526*404b540aSrobert 527*404b540aSrobert extern const char *pex_one (int flags, const char *executable, 528*404b540aSrobert char * const *argv, const char *pname, 529*404b540aSrobert const char *outname, const char *errname, 530*404b540aSrobert int *status, int *err); 531*404b540aSrobert 532*404b540aSrobert /* pexecute and pwait are the old pexecute interface, still here for 533*404b540aSrobert backward compatibility. Don't use these for new code. Instead, 534*404b540aSrobert use pex_init/pex_run/pex_get_status/pex_free, or pex_one. */ 535*404b540aSrobert 536*404b540aSrobert /* Definitions used by the pexecute routine. */ 537*404b540aSrobert 538*404b540aSrobert #define PEXECUTE_FIRST 1 539*404b540aSrobert #define PEXECUTE_LAST 2 540*404b540aSrobert #define PEXECUTE_ONE (PEXECUTE_FIRST + PEXECUTE_LAST) 541*404b540aSrobert #define PEXECUTE_SEARCH 4 542*404b540aSrobert #define PEXECUTE_VERBOSE 8 543*404b540aSrobert 544*404b540aSrobert /* Execute a program. */ 545*404b540aSrobert 546*404b540aSrobert extern int pexecute (const char *, char * const *, const char *, 547*404b540aSrobert const char *, char **, char **, int); 548*404b540aSrobert 549*404b540aSrobert /* Wait for pexecute to finish. */ 550*404b540aSrobert 551*404b540aSrobert extern int pwait (int, int *, int); 552*404b540aSrobert 553*404b540aSrobert #if !HAVE_DECL_ASPRINTF 554*404b540aSrobert /* Like sprintf but provides a pointer to malloc'd storage, which must 555*404b540aSrobert be freed by the caller. */ 556*404b540aSrobert 557*404b540aSrobert extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2; 558*404b540aSrobert #endif 559*404b540aSrobert 560*404b540aSrobert #if !HAVE_DECL_VASPRINTF 561*404b540aSrobert /* Like vsprintf but provides a pointer to malloc'd storage, which 562*404b540aSrobert must be freed by the caller. */ 563*404b540aSrobert 564*404b540aSrobert extern int vasprintf (char **, const char *, va_list) ATTRIBUTE_PRINTF(2,0); 565*404b540aSrobert #endif 566*404b540aSrobert 567*404b540aSrobert #if defined(HAVE_DECL_SNPRINTF) && !HAVE_DECL_SNPRINTF 568*404b540aSrobert /* Like sprintf but prints at most N characters. */ 569*404b540aSrobert extern int snprintf (char *, size_t, const char *, ...) ATTRIBUTE_PRINTF_3; 570*404b540aSrobert #endif 571*404b540aSrobert 572*404b540aSrobert #if defined(HAVE_DECL_VSNPRINTF) && !HAVE_DECL_VSNPRINTF 573*404b540aSrobert /* Like vsprintf but prints at most N characters. */ 574*404b540aSrobert extern int vsnprintf (char *, size_t, const char *, va_list) ATTRIBUTE_PRINTF(3,0); 575*404b540aSrobert #endif 576*404b540aSrobert 577*404b540aSrobert #if defined(HAVE_DECL_STRVERSCMP) && !HAVE_DECL_STRVERSCMP 578*404b540aSrobert /* Compare version strings. */ 579*404b540aSrobert extern int strverscmp (const char *, const char *); 580*404b540aSrobert #endif 581*404b540aSrobert 582*404b540aSrobert #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) 583*404b540aSrobert 584*404b540aSrobert /* Drastically simplified alloca configurator. If we're using GCC, 585*404b540aSrobert we use __builtin_alloca; otherwise we use the C alloca. The C 586*404b540aSrobert alloca is always available. You can override GCC by defining 587*404b540aSrobert USE_C_ALLOCA yourself. The canonical autoconf macro C_ALLOCA is 588*404b540aSrobert also set/unset as it is often used to indicate whether code needs 589*404b540aSrobert to call alloca(0). */ 590*404b540aSrobert extern void *C_alloca (size_t) ATTRIBUTE_MALLOC; 591*404b540aSrobert #undef alloca 592*404b540aSrobert #if GCC_VERSION >= 2000 && !defined USE_C_ALLOCA 593*404b540aSrobert # define alloca(x) __builtin_alloca(x) 594*404b540aSrobert # undef C_ALLOCA 595*404b540aSrobert # define ASTRDUP(X) \ 596*404b540aSrobert (__extension__ ({ const char *const libiberty_optr = (X); \ 597*404b540aSrobert const unsigned long libiberty_len = strlen (libiberty_optr) + 1; \ 598*404b540aSrobert char *const libiberty_nptr = (char *const) alloca (libiberty_len); \ 599*404b540aSrobert (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len); })) 600*404b540aSrobert #else 601*404b540aSrobert # define alloca(x) C_alloca(x) 602*404b540aSrobert # undef USE_C_ALLOCA 603*404b540aSrobert # define USE_C_ALLOCA 1 604*404b540aSrobert # undef C_ALLOCA 605*404b540aSrobert # define C_ALLOCA 1 606*404b540aSrobert extern const char *libiberty_optr; 607*404b540aSrobert extern char *libiberty_nptr; 608*404b540aSrobert extern unsigned long libiberty_len; 609*404b540aSrobert # define ASTRDUP(X) \ 610*404b540aSrobert (libiberty_optr = (X), \ 611*404b540aSrobert libiberty_len = strlen (libiberty_optr) + 1, \ 612*404b540aSrobert libiberty_nptr = (char *) alloca (libiberty_len), \ 613*404b540aSrobert (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len)) 614*404b540aSrobert #endif 615*404b540aSrobert 616*404b540aSrobert #ifdef __cplusplus 617*404b540aSrobert } 618*404b540aSrobert #endif 619*404b540aSrobert 620*404b540aSrobert 621*404b540aSrobert #endif /* ! defined (LIBIBERTY_H) */ 622