aboutsummaryrefslogtreecommitdiff
path: root/libiberty/pex-common.h
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@airs.com>2005-03-29 02:15:24 +0000
committerIan Lance Taylor <ian@airs.com>2005-03-29 02:15:24 +0000
commitb109e79adcb0d7e31737de397f97fa41d1d4e528 (patch)
treea736649abb8979bed53a6148d8360dbaf90ef9b5 /libiberty/pex-common.h
parent3d0dfe269d9f4b46ab3f0d07c026ae3fccf4338a (diff)
downloadgdb-b109e79adcb0d7e31737de397f97fa41d1d4e528.zip
gdb-b109e79adcb0d7e31737de397f97fa41d1d4e528.tar.gz
gdb-b109e79adcb0d7e31737de397f97fa41d1d4e528.tar.bz2
libiberty:
* pex-common.c: New file. * pex-one.c: New file. * pexecute.c: New file. * pex-common.h: Include <stdio.h>. (struct pex_obj): Define. (struct pex_funcs): Define. (pex_init_common): Declare. * pex-unix.c: Rewrite. * pex-win32.c: Rewrite. * pex-djgpp.c: Rewrite. * pex-msdos.c: Rewrite. * testsuite/text-pexecute.c: New file. * pexecute.txh: Rewrite. * configure.ac: Check for wait3 and wait4. Set CHECK to really-check rather than check-cplus-dem. * functions.texi: Rebuild. * Makefile.in: Rebuild dependencies. (CFILES): Add pexecute.c, pex-common.c, pex-one.c. (REQUIRED_OFILES): Add pexecute.o, pex-common.o, pex-one.o. * testsuite/Makefile.in (really-check): New target. (check-pexecute, test-pexecute): New targets. * configure: Rebuild. include: * libiberty.h: Include <stdio.h>. (PEX_RECORD_TIMES, PEX_USE_PIPES, PEX_SAVE_TEMPS): Define. (PEX_LAST, PEX_SEARCH, PEX_SUFFIX, PEX_STDERR_TO_STDOUT): Define. (PEX_BINARY_INPUT, PEX_BINARY_OUTPUT): Define. (pex_init, pex_run, pex_read_output): Declare. (pex_get_status, pex_get_times, pex_free, pex_one): Declare. (struct pex_time): Define.
Diffstat (limited to 'libiberty/pex-common.h')
-rw-r--r--libiberty/pex-common.h84
1 files changed, 84 insertions, 0 deletions
diff --git a/libiberty/pex-common.h b/libiberty/pex-common.h
index df3c0f6..c0b47fe 100644
--- a/libiberty/pex-common.h
+++ b/libiberty/pex-common.h
@@ -24,6 +24,7 @@ Boston, MA 02111-1307, USA. */
#include "config.h"
#include "libiberty.h"
+#include <stdio.h>
#define install_error_msg "installation problem, cannot exec `%s'"
@@ -42,4 +43,87 @@ Boston, MA 02111-1307, USA. */
/* value of `pipe': port index for writing. */
#define WRITE_PORT 1
+/* The structure used by pex_init and friends. */
+
+struct pex_obj
+{
+ /* Flags. */
+ int flags;
+ /* Name of calling program, for error messages. */
+ const char *pname;
+ /* Base name to use for temporary files. */
+ const char *tempbase;
+ /* Pipe to use as stdin for next process. */
+ int next_input;
+ /* File name to use as stdin for next process. */
+ char *next_input_name;
+ /* Whether next_input_name was allocated using malloc. */
+ int next_input_name_allocated;
+ /* Number of child processes. */
+ int count;
+ /* PIDs of child processes; array allocated using maloc. */
+ long *children;
+ /* Exit statuses of child processes; array allocated using malloc. */
+ int *status;
+ /* Time used by child processes; array allocated using malloc. */
+ struct pex_time *time;
+ /* Number of children we have already waited for. */
+ int number_waited;
+ /* FILE created by pex_read_output. */
+ FILE *read_output;
+ /* Number of temporary files to remove. */
+ int remove_count;
+ /* List of temporary files to remove; array allocated using malloc
+ of strings allocated using malloc. */
+ char **remove;
+ /* Pointers to system dependent functions. */
+ const struct pex_funcs *funcs;
+ /* For use by system dependent code. */
+ void *sysdep;
+};
+
+/* Functions passed to pex_run_common. */
+
+struct pex_funcs
+{
+ /* Open file NAME for reading. If BINARY is non-zero, open in
+ binary mode. Return >= 0 on success, -1 on error. */
+ int (*open_read) (struct pex_obj *, const char *name, int binary);
+ /* Open file NAME for writing. If BINARY is non-zero, open in
+ binary mode. Return >= 0 on success, -1 on error. */
+ int (*open_write) (struct pex_obj *, const char *name, int binary);
+ /* Execute a child process. FLAGS, EXECUTABLE, ARGV, ERR are from
+ pex_run. IN, OUT, ERRDES are each a descriptor, from open_read,
+ open_write, or pipe, or they are one of STDIN_FILE_NO,
+ STDOUT_FILE_NO or STDERR_FILE_NO; if not STD*_FILE_NO, they
+ should be closed. The function should handle the
+ PEX_STDERR_TO_STDOUT flag. Return >= 0 on success, or -1 on
+ error and set *ERRMSG and *ERR. */
+ long (*exec_child) (struct pex_obj *, int flags, const char *executable,
+ char * const * argv, int in, int out, int errdes,
+ const char **errmsg, int *err);
+ /* Close a descriptor. Return 0 on success, -1 on error. */
+ int (*close) (struct pex_obj *, int);
+ /* Wait for a child to complete, returning exit status in *STATUS
+ and time in *TIME (if it is not null). CHILD is from fork. DONE
+ is 1 if this is called via pex_free. ERRMSG and ERR are as in
+ fork. Return 0 on success, -1 on error. */
+ int (*wait) (struct pex_obj *, long, int *status, struct pex_time *time,
+ int done, const char **errmsg, int *err);
+ /* Create a pipe (only called if PEX_USE_PIPES is set) storing two
+ descriptin in *P. If BINARY is non-zero, open in binary mode.
+ Return 0 on success, -1 on error. */
+ int (*pipe) (struct pex_obj *, int *p, int binary);
+ /* Get a FILE pointer to read from a file descriptor (only called if
+ PEX_USE_PIPES is set). If BINARY is non-zero, open in binary
+ mode. Return pointer on success, NULL on error. */
+ FILE * (*fdopenr) (struct pex_obj *, int fd, int binary);
+ /* Free any system dependent data associated with OBJ. May be
+ NULL if there is nothing to do. */
+ void (*cleanup) (struct pex_obj *);
+};
+
+extern struct pex_obj *pex_init_common (int, const char *, const char *,
+ const struct pex_funcs *);
+
#endif