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