source: tests/process/child/child.c@ 919

Last change on this file since 919 was 919, checked in by Dmitry A. Kuminov, 14 years ago

tests/process/child: Added two new modes: 3 and 4.

Mode 3 prints everything it reads on stdin to stdout until read()
returns a failure. Mode 4 is similar but uses feof() and ferror()
to detect the end of input condition.

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <fcntl.h>
4
5int main(int argc, char *argv[])
6{
7 int n;
8 FILE *fp;
9 char buffer[4096];
10
11#ifdef __OS2__
12 _fsetmode(stdin, "b");
13 _fsetmode(stdout, "b");
14 _fsetmode(stderr, "b");
15#endif
16
17 if( argc > 2 )
18 {
19 switch( atoi( argv[1] ) )
20 {
21 case 0:
22 if( (fp = fopen(argv[2], "wb" )) != NULL )
23 {
24 while( (n = fread(buffer, 1, sizeof(buffer), stdin)) > 0 )
25 {
26 fwrite(buffer, 1, n, fp);
27 }
28
29 fclose( fp );
30 }
31
32 return 0;
33
34 case 1:
35 if( (fp = fopen(argv[2], "rb" )) != NULL )
36 {
37 while( (n = fread(buffer, 1, sizeof(buffer), fp)) > 0 )
38 {
39 fwrite(buffer, 1, n, stdout);
40 }
41
42 fclose( fp );
43 }
44
45 return 0;
46
47 case 2:
48 if( (fp = fopen(argv[2], "rb" )) != NULL )
49 {
50 while( (n = fread(buffer, 1, sizeof(buffer), fp)) > 0 )
51 {
52 fwrite(buffer, 1, n, stderr);
53 }
54
55 fclose( fp );
56 }
57
58 return 0;
59 }
60 }
61 else if (argc == 2)
62 {
63 switch (atoi (argv[1]))
64 {
65 case 3:
66 while ((n = fread (buffer, 1, sizeof (buffer), stdin)) > 0)
67 {
68 fwrite (buffer, 1, n, stdout);
69 }
70
71 return 0;
72
73 case 4:
74 while (!feof (stdin) && !ferror (stdin))
75 {
76 n = fread (buffer, 1, sizeof (buffer), stdin);
77 fwrite (buffer, 1, n, stdout);
78 }
79
80 return 0;
81 }
82 }
83
84 return -1;
85}
Note: See TracBrowser for help on using the repository browser.