xref: /titanic_52/usr/src/cmd/refer/refer3.c (revision 84ab085a13f931bc78e7415e7ce921dbaa14fcb3)
1 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
2 /*	  All Rights Reserved  	*/
3 
4 
5 /*
6  * Copyright (c) 1980 Regents of the University of California.
7  * All rights reserved. The Berkeley software License Agreement
8  * specifies the terms and conditions for redistribution.
9  */
10 
11 /*
12  * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
13  * All Rights Reserved.
14  */
15 
16 #pragma ident	"%Z%%M%	%I%	%E% SMI"
17 
18 #include "refer..c"
19 #define move(x, y) close(y); dup(x); close(x);
20 
21 corout(in, out, rprog, arg, outlen)
22 char *in, *out, *rprog;
23 {
24 	int pipev[2], fr1, fr2, fw1, fw2, n;
25 	int status;
26 
27 	pipe(pipev);
28 	fr1 = pipev[0];
29 	fw1 = pipev[1];
30 	pipe(pipev);
31 	fr2 = pipev[0];
32 	fw2 = pipev[1];
33 	if (fork() == 0)
34 	{
35 		close(fw1);
36 		close(fr2);
37 		move(fr1, 0);
38 		move(fw2, 1);
39 		execl(rprog, "deliv", arg, 0);
40 		err("Can't run %s", rprog);
41 	}
42 	close(fw2);
43 	close(fr1);
44 	write(fw1, in , strlen(in));
45 	close(fw1);
46 	wait(&status);
47 	n = read(fr2, out, outlen);
48 	out[n] = 0;
49 	close(fr2);
50 	return(n);
51 }
52