libiberty.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. /* Function declarations for libiberty.
  2. Copyright (C) 1997-2022 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 * const *) 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 * const *, FILE *);
  64. /* Return the number of elements in argv. */
  65. extern int countargv (char * const *);
  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. /* Return true when FD file descriptor exists. */
  100. extern int is_valid_fd (int fd);
  101. /* Concatenate an arbitrary number of strings. You must pass NULL as
  102. the last argument of this function, to terminate the list of
  103. strings. Allocates memory using xmalloc. */
  104. extern char *concat (const char *, ...) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_SENTINEL;
  105. /* Concatenate an arbitrary number of strings. You must pass NULL as
  106. the last argument of this function, to terminate the list of
  107. strings. Allocates memory using xmalloc. The first argument is
  108. not one of the strings to be concatenated, but if not NULL is a
  109. pointer to be freed after the new string is created, similar to the
  110. way xrealloc works. */
  111. extern char *reconcat (char *, const char *, ...) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_SENTINEL;
  112. /* Determine the length of concatenating an arbitrary number of
  113. strings. You must pass NULL as the last argument of this function,
  114. to terminate the list of strings. */
  115. extern unsigned long concat_length (const char *, ...) ATTRIBUTE_SENTINEL;
  116. /* Concatenate an arbitrary number of strings into a SUPPLIED area of
  117. memory. You must pass NULL as the last argument of this function,
  118. to terminate the list of strings. The supplied memory is assumed
  119. to be large enough. */
  120. extern char *concat_copy (char *, const char *, ...) ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_NONNULL(1) ATTRIBUTE_SENTINEL;
  121. /* Concatenate an arbitrary number of strings into a GLOBAL area of
  122. memory. You must pass NULL as the last argument of this function,
  123. to terminate the list of strings. The supplied memory is assumed
  124. to be large enough. */
  125. extern char *concat_copy2 (const char *, ...) ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_SENTINEL;
  126. /* This is the global area used by concat_copy2. */
  127. extern char *libiberty_concat_ptr;
  128. /* Concatenate an arbitrary number of strings. You must pass NULL as
  129. the last argument of this function, to terminate the list of
  130. strings. Allocates memory using alloca. The arguments are
  131. evaluated twice! */
  132. #define ACONCAT(ACONCAT_PARAMS) \
  133. (libiberty_concat_ptr = (char *) alloca (concat_length ACONCAT_PARAMS + 1), \
  134. concat_copy2 ACONCAT_PARAMS)
  135. /* Check whether two file descriptors refer to the same file. */
  136. extern int fdmatch (int fd1, int fd2);
  137. /* Return the position of the first bit set in the argument. */
  138. /* Prototypes vary from system to system, so we only provide a
  139. prototype on systems where we know that we need it. */
  140. #if defined (HAVE_DECL_FFS) && !HAVE_DECL_FFS
  141. extern int ffs(int);
  142. #endif
  143. /* Get the working directory. The result is cached, so don't call
  144. chdir() between calls to getpwd(). */
  145. extern char * getpwd (void);
  146. /* Get the current time. */
  147. /* Prototypes vary from system to system, so we only provide a
  148. prototype on systems where we know that we need it. */
  149. #ifdef __MINGW32__
  150. /* Forward declaration to avoid #include <sys/time.h>. */
  151. struct timeval;
  152. extern int gettimeofday (struct timeval *, void *);
  153. #endif
  154. /* Get the amount of time the process has run, in microseconds. */
  155. extern long get_run_time (void);
  156. /* Generate a relocated path to some installation directory. Allocates
  157. return value using malloc. */
  158. extern char *make_relative_prefix (const char *, const char *,
  159. const char *) ATTRIBUTE_MALLOC;
  160. /* Generate a relocated path to some installation directory without
  161. attempting to follow any soft links. Allocates
  162. return value using malloc. */
  163. extern char *make_relative_prefix_ignore_links (const char *, const char *,
  164. const char *) ATTRIBUTE_MALLOC;
  165. /* Returns a pointer to a directory path suitable for creating temporary
  166. files in. */
  167. extern const char *choose_tmpdir (void) ATTRIBUTE_RETURNS_NONNULL;
  168. /* Choose a temporary directory to use for scratch files. */
  169. extern char *choose_temp_base (void) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL;
  170. /* Return a temporary file name or NULL if unable to create one. */
  171. extern char *make_temp_file (const char *) ATTRIBUTE_MALLOC;
  172. /* Return a temporary file name with given PREFIX and SUFFIX
  173. or NULL if unable to create one. */
  174. extern char *make_temp_file_with_prefix (const char *, const char *) ATTRIBUTE_MALLOC;
  175. /* Remove a link to a file unless it is special. */
  176. extern int unlink_if_ordinary (const char *);
  177. /* Allocate memory filled with spaces. Allocates using malloc. */
  178. extern const char *spaces (int count);
  179. /* Return the maximum error number for which strerror will return a
  180. string. */
  181. extern int errno_max (void);
  182. /* Return the name of an errno value (e.g., strerrno (EINVAL) returns
  183. "EINVAL"). */
  184. extern const char *strerrno (int);
  185. /* Given the name of an errno value, return the value. */
  186. extern int strtoerrno (const char *);
  187. /* ANSI's strerror(), but more robust. */
  188. extern char *xstrerror (int) ATTRIBUTE_RETURNS_NONNULL;
  189. /* Return the maximum signal number for which strsignal will return a
  190. string. */
  191. extern int signo_max (void);
  192. /* Return a signal message string for a signal number
  193. (e.g., strsignal (SIGHUP) returns something like "Hangup"). */
  194. /* This is commented out as it can conflict with one in system headers.
  195. We still document its existence though. */
  196. /*extern const char *strsignal (int);*/
  197. /* Return the name of a signal number (e.g., strsigno (SIGHUP) returns
  198. "SIGHUP"). */
  199. extern const char *strsigno (int);
  200. /* Given the name of a signal, return its number. */
  201. extern int strtosigno (const char *);
  202. /* Register a function to be run by xexit. Returns 0 on success. */
  203. extern int xatexit (void (*fn) (void));
  204. /* Exit, calling all the functions registered with xatexit. */
  205. extern void xexit (int status) ATTRIBUTE_NORETURN;
  206. /* Set the program name used by xmalloc. */
  207. extern void xmalloc_set_program_name (const char *);
  208. /* Report an allocation failure. */
  209. extern void xmalloc_failed (size_t) ATTRIBUTE_NORETURN;
  210. /* Allocate memory without fail. If malloc fails, this will print a
  211. message to stderr (using the name set by xmalloc_set_program_name,
  212. if any) and then call xexit. */
  213. extern void *xmalloc (size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_RESULT_SIZE_1 ATTRIBUTE_WARN_UNUSED_RESULT;
  214. /* Reallocate memory without fail. This works like xmalloc. Note,
  215. realloc type functions are not suitable for attribute malloc since
  216. they may return the same address across multiple calls. */
  217. extern void *xrealloc (void *, size_t) ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_RESULT_SIZE_2 ATTRIBUTE_WARN_UNUSED_RESULT;
  218. /* Allocate memory without fail and set it to zero. This works like
  219. xmalloc. */
  220. extern void *xcalloc (size_t, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_RESULT_SIZE_1_2 ATTRIBUTE_WARN_UNUSED_RESULT;
  221. /* Copy a string into a memory buffer without fail. */
  222. extern char *xstrdup (const char *) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_WARN_UNUSED_RESULT;
  223. /* Copy at most N characters from string into a buffer without fail. */
  224. extern char *xstrndup (const char *, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_WARN_UNUSED_RESULT;
  225. /* Copy an existing memory buffer to a new memory buffer without fail. */
  226. extern void *xmemdup (const void *, size_t, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_WARN_UNUSED_RESULT;
  227. /* Physical memory routines. Return values are in BYTES. */
  228. extern double physmem_total (void);
  229. extern double physmem_available (void);
  230. /* Compute the 32-bit CRC of a block of memory. */
  231. extern unsigned int xcrc32 (const unsigned char *, int, unsigned int);
  232. /* These macros provide a K&R/C89/C++-friendly way of allocating structures
  233. with nice encapsulation. The XDELETE*() macros are technically
  234. superfluous, but provided here for symmetry. Using them consistently
  235. makes it easier to update client code to use different allocators such
  236. as new/delete and new[]/delete[]. */
  237. /* Scalar allocators. */
  238. #define XALLOCA(T) ((T *) alloca (sizeof (T)))
  239. #define XNEW(T) ((T *) xmalloc (sizeof (T)))
  240. #define XCNEW(T) ((T *) xcalloc (1, sizeof (T)))
  241. #define XDUP(T, P) ((T *) xmemdup ((P), sizeof (T), sizeof (T)))
  242. #define XDELETE(P) free ((void*) (P))
  243. /* Array allocators. */
  244. #define XALLOCAVEC(T, N) ((T *) alloca (sizeof (T) * (N)))
  245. #define XNEWVEC(T, N) ((T *) xmalloc (sizeof (T) * (N)))
  246. #define XCNEWVEC(T, N) ((T *) xcalloc ((N), sizeof (T)))
  247. #define XDUPVEC(T, P, N) ((T *) xmemdup ((P), sizeof (T) * (N), sizeof (T) * (N)))
  248. #define XRESIZEVEC(T, P, N) ((T *) xrealloc ((void *) (P), sizeof (T) * (N)))
  249. #define XDELETEVEC(P) free ((void*) (P))
  250. /* Allocators for variable-sized structures and raw buffers. */
  251. #define XALLOCAVAR(T, S) ((T *) alloca ((S)))
  252. #define XNEWVAR(T, S) ((T *) xmalloc ((S)))
  253. #define XCNEWVAR(T, S) ((T *) xcalloc (1, (S)))
  254. #define XDUPVAR(T, P, S1, S2) ((T *) xmemdup ((P), (S1), (S2)))
  255. #define XRESIZEVAR(T, P, S) ((T *) xrealloc ((P), (S)))
  256. /* Type-safe obstack allocator. */
  257. #define XOBNEW(O, T) ((T *) obstack_alloc ((O), sizeof (T)))
  258. #define XOBNEWVEC(O, T, N) ((T *) obstack_alloc ((O), sizeof (T) * (N)))
  259. #define XOBNEWVAR(O, T, S) ((T *) obstack_alloc ((O), (S)))
  260. #define XOBFINISH(O, T) ((T) obstack_finish ((O)))
  261. /* hex character manipulation routines */
  262. #define _hex_array_size 256
  263. #define _hex_bad 99
  264. extern const unsigned char _hex_value[_hex_array_size];
  265. extern void hex_init (void);
  266. #define hex_p(c) (hex_value (c) != _hex_bad)
  267. /* If you change this, note well: Some code relies on side effects in
  268. the argument being performed exactly once. */
  269. #define hex_value(c) ((unsigned int) _hex_value[(unsigned char) (c)])
  270. /* Flags for pex_init. These are bits to be or'ed together. */
  271. /* Record subprocess times, if possible. */
  272. #define PEX_RECORD_TIMES 0x1
  273. /* Use pipes for communication between processes, if possible. */
  274. #define PEX_USE_PIPES 0x2
  275. /* Save files used for communication between processes. */
  276. #define PEX_SAVE_TEMPS 0x4
  277. /* Max number of alloca bytes per call before we must switch to malloc.
  278. ?? Swiped from gnulib's regex_internal.h header. Is this actually
  279. the case? This number seems arbitrary, though sane.
  280. The OS usually guarantees only one guard page at the bottom of the stack,
  281. and a page size can be as small as 4096 bytes. So we cannot safely
  282. allocate anything larger than 4096 bytes. Also care for the possibility
  283. of a few compiler-allocated temporary stack slots. */
  284. #define MAX_ALLOCA_SIZE 4032
  285. /* Prepare to execute one or more programs, with standard output of
  286. each program fed to standard input of the next.
  287. FLAGS As above.
  288. PNAME The name of the program to report in error messages.
  289. TEMPBASE A base name to use for temporary files; may be NULL to
  290. use a random name.
  291. Returns NULL on error. */
  292. extern struct pex_obj *pex_init (int flags, const char *pname,
  293. const char *tempbase) ATTRIBUTE_RETURNS_NONNULL;
  294. /* Flags for pex_run. These are bits to be or'ed together. */
  295. /* Last program in pipeline. Standard output of program goes to
  296. OUTNAME, or, if OUTNAME is NULL, to standard output of caller. Do
  297. not set this if you want to call pex_read_output. After this is
  298. set, pex_run may no longer be called with the same struct
  299. pex_obj. */
  300. #define PEX_LAST 0x1
  301. /* Search for program in executable search path. */
  302. #define PEX_SEARCH 0x2
  303. /* OUTNAME is a suffix. */
  304. #define PEX_SUFFIX 0x4
  305. /* Send program's standard error to standard output. */
  306. #define PEX_STDERR_TO_STDOUT 0x8
  307. /* Input file should be opened in binary mode. This flag is ignored
  308. on Unix. */
  309. #define PEX_BINARY_INPUT 0x10
  310. /* Output file should be opened in binary mode. This flag is ignored
  311. on Unix. For proper behaviour PEX_BINARY_INPUT and
  312. PEX_BINARY_OUTPUT have to match appropriately--i.e., a call using
  313. PEX_BINARY_OUTPUT should be followed by a call using
  314. PEX_BINARY_INPUT. */
  315. #define PEX_BINARY_OUTPUT 0x20
  316. /* Capture stderr to a pipe. The output can be read by
  317. calling pex_read_err and reading from the returned
  318. FILE object. This flag may be specified only for
  319. the last program in a pipeline.
  320. This flag is supported only on Unix and Windows. */
  321. #define PEX_STDERR_TO_PIPE 0x40
  322. /* Capture stderr in binary mode. This flag is ignored
  323. on Unix. */
  324. #define PEX_BINARY_ERROR 0x80
  325. /* Append stdout to existing file instead of truncating it. */
  326. #define PEX_STDOUT_APPEND 0x100
  327. /* Thes same as PEX_STDOUT_APPEND, but for STDERR. */
  328. #define PEX_STDERR_APPEND 0x200
  329. /* Execute one program. Returns NULL on success. On error returns an
  330. error string (typically just the name of a system call); the error
  331. string is statically allocated.
  332. OBJ Returned by pex_init.
  333. FLAGS As above.
  334. EXECUTABLE The program to execute.
  335. ARGV NULL terminated array of arguments to pass to the program.
  336. OUTNAME Sets the output file name as follows:
  337. PEX_SUFFIX set (OUTNAME may not be NULL):
  338. TEMPBASE parameter to pex_init not NULL:
  339. Output file name is the concatenation of TEMPBASE
  340. and OUTNAME.
  341. TEMPBASE is NULL:
  342. Output file name is a random file name ending in
  343. OUTNAME.
  344. PEX_SUFFIX not set:
  345. OUTNAME not NULL:
  346. Output file name is OUTNAME.
  347. OUTNAME NULL, TEMPBASE not NULL:
  348. Output file name is randomly chosen using
  349. TEMPBASE.
  350. OUTNAME NULL, TEMPBASE NULL:
  351. Output file name is randomly chosen.
  352. If PEX_LAST is not set, the output file name is the
  353. name to use for a temporary file holding stdout, if
  354. any (there will not be a file if PEX_USE_PIPES is set
  355. and the system supports pipes). If a file is used, it
  356. will be removed when no longer needed unless
  357. PEX_SAVE_TEMPS is set.
  358. If PEX_LAST is set, and OUTNAME is not NULL, standard
  359. output is written to the output file name. The file
  360. will not be removed. If PEX_LAST and PEX_SUFFIX are
  361. both set, TEMPBASE may not be NULL.
  362. ERRNAME If not NULL, this is the name of a file to which
  363. standard error is written. If NULL, standard error of
  364. the program is standard error of the caller.
  365. ERR On an error return, *ERR is set to an errno value, or
  366. to 0 if there is no relevant errno.
  367. */
  368. extern const char *pex_run (struct pex_obj *obj, int flags,
  369. const char *executable, char * const *argv,
  370. const char *outname, const char *errname,
  371. int *err);
  372. /* As for pex_run (), but takes an extra parameter to enable the
  373. environment for the child process to be specified.
  374. ENV The environment for the child process, specified as
  375. an array of character pointers. Each element of the
  376. array should point to a string of the form VAR=VALUE,
  377. with the exception of the last element which must be
  378. a null pointer.
  379. */
  380. extern const char *pex_run_in_environment (struct pex_obj *obj, int flags,
  381. const char *executable,
  382. char * const *argv,
  383. char * const *env,
  384. const char *outname,
  385. const char *errname, int *err);
  386. /* Return a stream for a temporary file to pass to the first program
  387. in the pipeline as input. The file name is chosen as for pex_run.
  388. pex_run closes the file automatically; don't close it yourself. */
  389. extern FILE *pex_input_file (struct pex_obj *obj, int flags,
  390. const char *in_name);
  391. /* Return a stream for a pipe connected to the standard input of the
  392. first program in the pipeline. You must have passed
  393. `PEX_USE_PIPES' to `pex_init'. Close the returned stream
  394. yourself. */
  395. extern FILE *pex_input_pipe (struct pex_obj *obj, int binary);
  396. /* Read the standard output of the last program to be executed.
  397. pex_run cannot be called after this. BINARY should be non-zero if
  398. the file should be opened in binary mode; this is ignored on Unix.
  399. Returns NULL on error. Don't call fclose on the returned FILE; it
  400. will be closed by pex_free. */
  401. extern FILE *pex_read_output (struct pex_obj *, int binary);
  402. /* Read the standard error of the last program to be executed.
  403. pex_run cannot be called after this. BINARY should be non-zero if
  404. the file should be opened in binary mode; this is ignored on Unix.
  405. Returns NULL on error. Don't call fclose on the returned FILE; it
  406. will be closed by pex_free. */
  407. extern FILE *pex_read_err (struct pex_obj *, int binary);
  408. /* Return exit status of all programs in VECTOR. COUNT indicates the
  409. size of VECTOR. The status codes in the vector are in the order of
  410. the calls to pex_run. Returns 0 on error, 1 on success. */
  411. extern int pex_get_status (struct pex_obj *, int count, int *vector);
  412. /* Return times of all programs in VECTOR. COUNT indicates the size
  413. of VECTOR. struct pex_time is really just struct timeval, but that
  414. is not portable to all systems. Returns 0 on error, 1 on
  415. success. */
  416. struct pex_time
  417. {
  418. unsigned long user_seconds;
  419. unsigned long user_microseconds;
  420. unsigned long system_seconds;
  421. unsigned long system_microseconds;
  422. };
  423. extern int pex_get_times (struct pex_obj *, int count,
  424. struct pex_time *vector);
  425. /* Clean up a pex_obj. If you have not called pex_get_times or
  426. pex_get_status, this will try to kill the subprocesses. */
  427. extern void pex_free (struct pex_obj *);
  428. /* Just execute one program. Return value is as for pex_run.
  429. FLAGS Combination of PEX_SEARCH and PEX_STDERR_TO_STDOUT.
  430. EXECUTABLE As for pex_run.
  431. ARGV As for pex_run.
  432. PNAME As for pex_init.
  433. OUTNAME As for pex_run when PEX_LAST is set.
  434. ERRNAME As for pex_run.
  435. STATUS Set to exit status on success.
  436. ERR As for pex_run.
  437. */
  438. extern const char *pex_one (int flags, const char *executable,
  439. char * const *argv, const char *pname,
  440. const char *outname, const char *errname,
  441. int *status, int *err);
  442. /* pexecute and pwait are the old pexecute interface, still here for
  443. backward compatibility. Don't use these for new code. Instead,
  444. use pex_init/pex_run/pex_get_status/pex_free, or pex_one. */
  445. /* Definitions used by the pexecute routine. */
  446. #define PEXECUTE_FIRST 1
  447. #define PEXECUTE_LAST 2
  448. #define PEXECUTE_ONE (PEXECUTE_FIRST + PEXECUTE_LAST)
  449. #define PEXECUTE_SEARCH 4
  450. #define PEXECUTE_VERBOSE 8
  451. /* Execute a program. */
  452. extern int pexecute (const char *, char * const *, const char *,
  453. const char *, char **, char **, int);
  454. /* Wait for pexecute to finish. */
  455. extern int pwait (int, int *, int);
  456. /* Like bsearch, but takes and passes on an argument like qsort_r. */
  457. extern void *bsearch_r (const void *, const void *,
  458. size_t, size_t,
  459. int (*)(const void *, const void *, void *),
  460. void *);
  461. #if defined(HAVE_DECL_ASPRINTF) && !HAVE_DECL_ASPRINTF
  462. /* Like sprintf but provides a pointer to malloc'd storage, which must
  463. be freed by the caller. */
  464. extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2;
  465. #endif
  466. /* Like asprintf but allocates memory without fail. This works like
  467. xmalloc. */
  468. extern char *xasprintf (const char *, ...) ATTRIBUTE_MALLOC ATTRIBUTE_PRINTF_1;
  469. #if defined(HAVE_DECL_VASPRINTF) && !HAVE_DECL_VASPRINTF
  470. /* Like vsprintf but provides a pointer to malloc'd storage, which
  471. must be freed by the caller. */
  472. extern int vasprintf (char **, const char *, va_list) ATTRIBUTE_PRINTF(2,0);
  473. #endif
  474. /* Like vasprintf but allocates memory without fail. This works like
  475. xmalloc. */
  476. extern char *xvasprintf (const char *, va_list) ATTRIBUTE_MALLOC ATTRIBUTE_PRINTF(1,0);
  477. #if defined(HAVE_DECL_SNPRINTF) && !HAVE_DECL_SNPRINTF
  478. /* Like sprintf but prints at most N characters. */
  479. extern int snprintf (char *, size_t, const char *, ...) ATTRIBUTE_PRINTF_3;
  480. #endif
  481. #if defined(HAVE_DECL_VSNPRINTF) && !HAVE_DECL_VSNPRINTF
  482. /* Like vsprintf but prints at most N characters. */
  483. extern int vsnprintf (char *, size_t, const char *, va_list) ATTRIBUTE_PRINTF(3,0);
  484. #endif
  485. #if defined (HAVE_DECL_STRNLEN) && !HAVE_DECL_STRNLEN
  486. extern size_t strnlen (const char *, size_t);
  487. #endif
  488. #if defined(HAVE_DECL_STRVERSCMP) && !HAVE_DECL_STRVERSCMP
  489. /* Compare version strings. */
  490. extern int strverscmp (const char *, const char *);
  491. #endif
  492. #if defined(HAVE_DECL_STRTOL) && !HAVE_DECL_STRTOL
  493. extern long int strtol (const char *nptr,
  494. char **endptr, int base);
  495. #endif
  496. #if defined(HAVE_DECL_STRTOUL) && !HAVE_DECL_STRTOUL
  497. extern unsigned long int strtoul (const char *nptr,
  498. char **endptr, int base);
  499. #endif
  500. #if defined(HAVE_LONG_LONG) && defined(HAVE_DECL_STRTOLL) && !HAVE_DECL_STRTOLL
  501. __extension__
  502. extern long long int strtoll (const char *nptr,
  503. char **endptr, int base);
  504. #endif
  505. #if defined(HAVE_LONG_LONG) && defined(HAVE_DECL_STRTOULL) && !HAVE_DECL_STRTOULL
  506. __extension__
  507. extern unsigned long long int strtoull (const char *nptr,
  508. char **endptr, int base);
  509. #endif
  510. /* Set the title of a process */
  511. extern void setproctitle (const char *name, ...);
  512. /* Increase stack limit if possible. */
  513. extern void stack_limit_increase (unsigned long);
  514. #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
  515. /* Drastically simplified alloca configurator. If we're using GCC,
  516. we use __builtin_alloca; otherwise we use the C alloca. The C
  517. alloca is always available. You can override GCC by defining
  518. USE_C_ALLOCA yourself. The canonical autoconf macro C_ALLOCA is
  519. also set/unset as it is often used to indicate whether code needs
  520. to call alloca(0). */
  521. extern void *C_alloca (size_t) ATTRIBUTE_MALLOC;
  522. #undef alloca
  523. #if GCC_VERSION >= 2000 && !defined USE_C_ALLOCA
  524. # define alloca(x) __builtin_alloca(x)
  525. # undef C_ALLOCA
  526. # define ASTRDUP(X) \
  527. (__extension__ ({ const char *const libiberty_optr = (X); \
  528. const unsigned long libiberty_len = strlen (libiberty_optr) + 1; \
  529. char *const libiberty_nptr = (char *) alloca (libiberty_len); \
  530. (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len); }))
  531. #else
  532. # define alloca(x) C_alloca(x)
  533. # undef USE_C_ALLOCA
  534. # define USE_C_ALLOCA 1
  535. # undef C_ALLOCA
  536. # define C_ALLOCA 1
  537. extern const char *libiberty_optr;
  538. extern char *libiberty_nptr;
  539. extern unsigned long libiberty_len;
  540. # define ASTRDUP(X) \
  541. (libiberty_optr = (X), \
  542. libiberty_len = strlen (libiberty_optr) + 1, \
  543. libiberty_nptr = (char *) alloca (libiberty_len), \
  544. (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len))
  545. #endif
  546. #ifdef __cplusplus
  547. }
  548. #endif
  549. #endif /* ! defined (LIBIBERTY_H) */