1 |
greg |
1.1 |
#ifndef lint |
2 |
schorsch |
2.7 |
static const char RCSid[] = "$Id: process.c,v 2.6 2003/02/25 02:47:21 greg Exp $"; |
3 |
greg |
1.1 |
#endif |
4 |
|
|
/* |
5 |
|
|
* Routines to communicate with separate process via dual pipes |
6 |
greg |
2.5 |
* |
7 |
|
|
* External symbols declared in standard.h |
8 |
|
|
*/ |
9 |
|
|
|
10 |
greg |
2.6 |
#include "copyright.h" |
11 |
greg |
1.1 |
|
12 |
schorsch |
2.7 |
#include "rtprocess.h" |
13 |
greg |
1.1 |
|
14 |
schorsch |
2.7 |
/* |
15 |
greg |
1.1 |
|
16 |
schorsch |
2.7 |
The functions open_process() and close_process() exist in |
17 |
|
|
(currently) two versions, which are found in the files: |
18 |
greg |
1.1 |
|
19 |
schorsch |
2.7 |
win_process.c |
20 |
|
|
unix_process.c |
21 |
greg |
1.1 |
|
22 |
schorsch |
2.7 |
*/ |
23 |
greg |
2.4 |
|
24 |
greg |
1.1 |
int |
25 |
schorsch |
2.7 |
process( /* process data through pd */ |
26 |
|
|
SUBPROC *pd, |
27 |
|
|
char *recvbuf, char *sendbuf, |
28 |
|
|
int nbr, int nbs |
29 |
|
|
) |
30 |
greg |
1.1 |
{ |
31 |
|
|
if (nbs > PIPE_BUF) |
32 |
|
|
return(-1); |
33 |
schorsch |
2.7 |
if (writebuf(pd->w, sendbuf, nbs) < nbs) |
34 |
greg |
1.1 |
return(-1); |
35 |
schorsch |
2.7 |
return(readbuf(pd->r, recvbuf, nbr)); |
36 |
greg |
1.1 |
} |
37 |
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
int |
41 |
schorsch |
2.7 |
readbuf( /* read all of requested buffer */ |
42 |
|
|
int fd, |
43 |
|
|
char *bpos, |
44 |
|
|
int siz |
45 |
|
|
) |
46 |
greg |
1.1 |
{ |
47 |
greg |
2.3 |
register int cc = 0, nrem = siz; |
48 |
greg |
2.4 |
retry: |
49 |
greg |
1.1 |
while (nrem > 0 && (cc = read(fd, bpos, nrem)) > 0) { |
50 |
|
|
bpos += cc; |
51 |
|
|
nrem -= cc; |
52 |
|
|
} |
53 |
greg |
2.4 |
if (cc < 0) { |
54 |
|
|
#ifndef BSD |
55 |
|
|
if (errno == EINTR) /* we were interrupted! */ |
56 |
|
|
goto retry; |
57 |
|
|
#endif |
58 |
greg |
1.1 |
return(cc); |
59 |
greg |
2.4 |
} |
60 |
greg |
1.1 |
return(siz-nrem); |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
|
64 |
|
|
int |
65 |
schorsch |
2.7 |
writebuf( /* write all of requested buffer */ |
66 |
|
|
int fd, |
67 |
|
|
char *bpos, |
68 |
|
|
int siz |
69 |
|
|
) |
70 |
greg |
1.1 |
{ |
71 |
greg |
2.3 |
register int cc = 0, nrem = siz; |
72 |
greg |
2.4 |
retry: |
73 |
greg |
1.1 |
while (nrem > 0 && (cc = write(fd, bpos, nrem)) > 0) { |
74 |
|
|
bpos += cc; |
75 |
|
|
nrem -= cc; |
76 |
|
|
} |
77 |
greg |
2.4 |
if (cc < 0) { |
78 |
|
|
#ifndef BSD |
79 |
|
|
if (errno == EINTR) /* we were interrupted! */ |
80 |
|
|
goto retry; |
81 |
|
|
#endif |
82 |
greg |
1.1 |
return(cc); |
83 |
greg |
2.4 |
} |
84 |
greg |
1.1 |
return(siz-nrem); |
85 |
|
|
} |