ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/process.c
(Generate patch)

Comparing ray/src/common/process.c (file contents):
Revision 2.6 by greg, Tue Feb 25 02:47:21 2003 UTC vs.
Revision 2.7 by schorsch, Thu Jun 26 00:58:09 2003 UTC

# Line 9 | Line 9 | static const char      RCSid[] = "$Id$";
9  
10   #include "copyright.h"
11  
12 <                                /* find pipe buffer limit */
13 < #include  <sys/param.h>
12 > #include "rtprocess.h"
13  
14 < #ifndef PIPE_BUF
16 < #ifdef PIPSIZ
17 < #define PIPE_BUF        PIPSIZ
18 < #else
19 < #ifdef PIPE_MAX
20 < #define PIPE_BUF        PIPE_MAX
21 < #else
22 < #define PIPE_BUF        512             /* hyperconservative */
23 < #endif
24 < #endif
25 < #endif
14 > /*
15  
16 < #include  "vfork.h"
16 > The functions open_process() and close_process() exist in
17 > (currently) two versions, which are found in the files:
18  
19 < #ifndef BSD
20 < #include  <errno.h>
31 < #endif
19 >        win_process.c
20 >        unix_process.c
21  
22 + */
23  
24   int
25 < open_process(pd, av)            /* open communication to separate process */
26 < int     pd[3];
27 < char    *av[];
25 > process(                /* process data through pd */
26 > SUBPROC *pd,
27 > char    *recvbuf, char *sendbuf,
28 > int     nbr, int nbs
29 > )
30   {
39        extern char     *getpath(), *getenv();
40        char    *compath;
41        int     p0[2], p1[2];
42                                        /* find executable */
43        compath = getpath(av[0], getenv("PATH"), 1);
44        if (compath == 0)
45                return(0);
46        if (pipe(p0) < 0 || pipe(p1) < 0)
47                return(-1);
48        if ((pd[2] = vfork()) == 0) {           /* if child */
49                close(p0[1]);
50                close(p1[0]);
51                if (p0[0] != 0) {       /* connect p0 to stdin */
52                        dup2(p0[0], 0);
53                        close(p0[0]);
54                }
55                if (p1[1] != 1) {       /* connect p1 to stdout */
56                        dup2(p1[1], 1);
57                        close(p1[1]);
58                }
59                execv(compath, av);     /* exec command */
60                perror(compath);
61                _exit(127);
62        }
63        if (pd[2] == -1)
64                return(-1);
65        close(p0[0]);
66        close(p1[1]);
67        pd[0] = p1[0];
68        pd[1] = p0[1];
69        return(PIPE_BUF);
70 }
71
72
73 int
74 process(pd, recvbuf, sendbuf, nbr, nbs)         /* process data through pd */
75 int     pd[3];
76 char    *recvbuf, *sendbuf;
77 int     nbr, nbs;
78 {
31          if (nbs > PIPE_BUF)
32                  return(-1);
33 <        if (writebuf(pd[1], sendbuf, nbs) < nbs)
33 >        if (writebuf(pd->w, sendbuf, nbs) < nbs)
34                  return(-1);
35 <        return(readbuf(pd[0], recvbuf, nbr));
35 >        return(readbuf(pd->r, recvbuf, nbr));
36   }
37  
38  
87 int
88 close_process(pd)               /* close pipes and wait for process */
89 int     pd[3];
90 {
91        int     pid, status;
39  
93        close(pd[1]);
94        close(pd[0]);
95        while ((pid = wait(&status)) != -1)
96                if (pid == pd[2])
97                        return(status>>8 & 0xff);
98        return(-1);             /* ? unknown status */
99 }
100
101
40   int
41 < readbuf(fd, bpos, siz)          /* read all of requested buffer */
42 < int     fd;
43 < char    *bpos;
44 < int     siz;
41 > readbuf(                /* read all of requested buffer */
42 > int     fd,
43 > char    *bpos,
44 > int     siz
45 > )
46   {
47          register int    cc = 0, nrem = siz;
48   retry:
# Line 123 | Line 62 | retry:
62  
63  
64   int
65 < writebuf(fd, bpos, siz)         /* write all of requested buffer */
66 < int     fd;
67 < char    *bpos;
68 < int     siz;
65 > writebuf(               /* write all of requested buffer */
66 > int     fd,
67 > char    *bpos,
68 > int     siz
69 > )
70   {
71          register int    cc = 0, nrem = siz;
72   retry:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines