libiberty.h 26 KB

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