No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / gdb6 / libiberty / pex-common.h
blob8ded138148c7aa11c72a6d33714ae7300780996f
1 /* Utilities to execute a program in a subprocess (possibly linked by pipes
2 with other subprocesses), and wait for it. Shared logic.
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004
4 Free Software Foundation, Inc.
6 This file is part of the libiberty library.
7 Libiberty is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 Libiberty is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with libiberty; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 #ifndef PEX_COMMON_H
23 #define PEX_COMMON_H
25 #include "config.h"
26 #include "libiberty.h"
27 #include <stdio.h>
29 #define install_error_msg "installation problem, cannot exec `%s'"
31 /* stdin file number. */
32 #define STDIN_FILE_NO 0
34 /* stdout file number. */
35 #define STDOUT_FILE_NO 1
37 /* stderr file number. */
38 #define STDERR_FILE_NO 2
40 /* value of `pipe': port index for reading. */
41 #define READ_PORT 0
43 /* value of `pipe': port index for writing. */
44 #define WRITE_PORT 1
46 /* The structure used by pex_init and friends. */
48 struct pex_obj
50 /* Flags. */
51 int flags;
52 /* Name of calling program, for error messages. */
53 const char *pname;
54 /* Base name to use for temporary files. */
55 const char *tempbase;
56 /* Pipe to use as stdin for next process. */
57 int next_input;
58 /* File name to use as stdin for next process. */
59 char *next_input_name;
60 /* Whether next_input_name was allocated using malloc. */
61 int next_input_name_allocated;
62 /* Number of child processes. */
63 int count;
64 /* PIDs of child processes; array allocated using malloc. */
65 long *children;
66 /* Exit statuses of child processes; array allocated using malloc. */
67 int *status;
68 /* Time used by child processes; array allocated using malloc. */
69 struct pex_time *time;
70 /* Number of children we have already waited for. */
71 int number_waited;
72 /* FILE created by pex_input_file. */
73 FILE *input_file;
74 /* FILE created by pex_read_output. */
75 FILE *read_output;
76 /* Number of temporary files to remove. */
77 int remove_count;
78 /* List of temporary files to remove; array allocated using malloc
79 of strings allocated using malloc. */
80 char **remove;
81 /* Pointers to system dependent functions. */
82 const struct pex_funcs *funcs;
83 /* For use by system dependent code. */
84 void *sysdep;
87 /* Functions passed to pex_run_common. */
89 struct pex_funcs
91 /* Open file NAME for reading. If BINARY is non-zero, open in
92 binary mode. Return >= 0 on success, -1 on error. */
93 int (*open_read) (struct pex_obj *, const char */* name */, int /* binary */);
94 /* Open file NAME for writing. If BINARY is non-zero, open in
95 binary mode. Return >= 0 on success, -1 on error. */
96 int (*open_write) (struct pex_obj *, const char */* name */,
97 int /* binary */);
98 /* Execute a child process. FLAGS, EXECUTABLE, ARGV, ERR are from
99 pex_run. IN, OUT, ERRDES are each a descriptor, from open_read,
100 open_write, or pipe, or they are one of STDIN_FILE_NO,
101 STDOUT_FILE_NO or STDERR_FILE_NO; if not STD*_FILE_NO, they
102 should be closed. The function should handle the
103 PEX_STDERR_TO_STDOUT flag. Return >= 0 on success, or -1 on
104 error and set *ERRMSG and *ERR. */
105 long (*exec_child) (struct pex_obj *, int /* flags */,
106 const char */* executable */, char * const * /* argv */,
107 int /* in */, int /* out */, int /* errdes */,
108 const char **/* errmsg */, int */* err */);
109 /* Close a descriptor. Return 0 on success, -1 on error. */
110 int (*close) (struct pex_obj *, int);
111 /* Wait for a child to complete, returning exit status in *STATUS
112 and time in *TIME (if it is not null). CHILD is from fork. DONE
113 is 1 if this is called via pex_free. ERRMSG and ERR are as in
114 fork. Return 0 on success, -1 on error. */
115 int (*wait) (struct pex_obj *, long /* child */, int * /* status */,
116 struct pex_time * /* time */, int /* done */,
117 const char ** /* errmsg */, int * /* err */);
118 /* Create a pipe (only called if PEX_USE_PIPES is set) storing two
119 descriptors in P[0] and P[1]. If BINARY is non-zero, open in
120 binary mode. Return 0 on success, -1 on error. */
121 int (*pipe) (struct pex_obj *, int * /* p */, int /* binary */);
122 /* Get a FILE pointer to read from a file descriptor (only called if
123 PEX_USE_PIPES is set). If BINARY is non-zero, open in binary
124 mode. Return pointer on success, NULL on error. */
125 FILE * (*fdopenr) (struct pex_obj *, int /* fd */, int /* binary */);
126 /* Get a FILE pointer to write to the file descriptor FD (only
127 called if PEX_USE_PIPES is set). If BINARY is non-zero, open in
128 binary mode. Arrange for FD not to be inherited by the child
129 processes. Return pointer on success, NULL on error. */
130 FILE * (*fdopenw) (struct pex_obj *, int /* fd */, int /* binary */);
131 /* Free any system dependent data associated with OBJ. May be
132 NULL if there is nothing to do. */
133 void (*cleanup) (struct pex_obj *);
136 extern struct pex_obj *pex_init_common (int, const char *, const char *,
137 const struct pex_funcs *);
139 #endif