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

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

tests/process/child: Added checking the stdin/out/err handle type.

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <fcntl.h>
4#include <io.h>
5
6#ifdef __OS2__
7
8#define INCL_DOSFILEMGR
9#include <os2.h>
10
11void doDosQueryHType(HFILE hfile)
12{
13 ULONG type, attr;
14 APIRET arc = DosQueryHType(hfile, &type, &attr);
15 if (arc == 0)
16 printf("DosQueryHType(%ld) type %lx attr %lx\r\n", hfile, type, attr);
17 else
18 printf("DosQueryHType(%ld) rc %ld\r\n", hfile, arc);
19}
20
21#endif
22
23int main(int argc, char *argv[])
24{
25 int n;
26 FILE *fp;
27 char buffer[4096];
28
29#ifdef __OS2__
30 _fsetmode(stdin, "b");
31 _fsetmode(stdout, "b");
32 _fsetmode(stderr, "b");
33#endif
34
35 printf("isatty(stdin) %d\r\n", isatty(fileno(stdin)));
36 printf("isatty(stdout) %d\r\n", isatty(fileno(stdout)));
37 printf("isatty(stderr) %d\r\n", isatty(fileno(stderr)));
38
39#ifdef __OS2__
40 doDosQueryHType((HFILE)0);
41 doDosQueryHType((HFILE)1);
42 doDosQueryHType((HFILE)2);
43#endif
44
45 if( argc > 2 )
46 {
47 switch( atoi( argv[1] ) )
48 {
49 case 0:
50 if( (fp = fopen(argv[2], "wb" )) != NULL )
51 {
52 while( (n = fread(buffer, 1, sizeof(buffer), stdin)) > 0 )
53 {
54 fwrite(buffer, 1, n, fp);
55 }
56
57 fclose( fp );
58 }
59
60 return 0;
61
62 case 1:
63 if( (fp = fopen(argv[2], "rb" )) != NULL )
64 {
65 while( (n = fread(buffer, 1, sizeof(buffer), fp)) > 0 )
66 {
67 fwrite(buffer, 1, n, stdout);
68 }
69
70 fclose( fp );
71 }
72
73 return 0;
74
75 case 2:
76 if( (fp = fopen(argv[2], "rb" )) != NULL )
77 {
78 while( (n = fread(buffer, 1, sizeof(buffer), fp)) > 0 )
79 {
80 fwrite(buffer, 1, n, stderr);
81 }
82
83 fclose( fp );
84 }
85
86 return 0;
87 }
88 }
89 else if (argc == 2)
90 {
91 switch (atoi (argv[1]))
92 {
93 case 3:
94 while ((n = fread (buffer, 1, sizeof (buffer), stdin)) > 0)
95 {
96 fwrite (buffer, 1, n, stdout);
97 }
98
99 return 0;
100
101 case 4:
102 while (!feof (stdin) && !ferror (stdin))
103 {
104 n = fread (buffer, 1, sizeof (buffer), stdin);
105 fwrite (buffer, 1, n, stdout);
106 }
107
108 return 0;
109 }
110 }
111
112 return -1;
113}
Note: See TracBrowser for help on using the repository browser.