forked from wenjun1055/c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
14.10.c
37 lines (31 loc) · 851 Bytes
/
14.10.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include <stdlib.h>
#include <stropts.h>
#include <unistd.h>
#define BUFFSIZE 4096
int main(void)
{
int n, flag;
char ctlbuf[BUFFSIZE], datbuf[BUFFSIZE];
struct strbuf ctl, dat;
ctl.buf = ctlbuf;
ctl.maxlen = BUFFSIZE;
dat.buf = datbuf;
dat.maxlen = BUFFSIZE;
for ( ; ;) {
flag = 0;
if ((n = getmsg(STDIN_FILENO, &ctl, &dat, &flag)) < 0) {
printf("getmsg error\n");
exit(-1);
}
fprintf(stderr, "flag = %d, ctl.len = %d, dat.len = %d\n", flag, ctl.len, dat.len);
if (dat.len == 0) {
exit(0);
} else if (dat.len > 0) {
if (write(STDOUT_FILENO, dat.buf, dat.len) != dat.len) {
printf("write error\n");
exit(-1);
}
}
}
}