1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5/*============================================================
6**
7** Source: createprocessa/test2/childprocess.c
8**
9** Purpose: This child process reads a string from stdin
10** and writes it out to stdout & stderr
11**
12** Dependencies: memset
13** fgets
14** gputs
15**
16
17**
18**=========================================================*/
19
20#include <palsuite.h>
21#include "test2.h"
22
23
24
25int __cdecl main( int argc, char **argv )
26{
27 int iRetCode = EXIT_OK_CODE; /* preset exit code to OK */
28 char szBuf[BUF_LEN];
29
30
31 if(0 != (PAL_Initialize(argc, argv)))
32 {
33 return FAIL;
34 }
35
36 if (argc != 4)
37 {
38 return EXIT_ERR_CODE3;
39 }
40
41 if (strcmp(argv[1], szArg1) != 0
42 || strcmp(argv[2], szArg2) != 0
43 || strcmp(argv[3], szArg3) != 0)
44 {
45 return EXIT_ERR_CODE4;
46 }
47
48
49 memset(szBuf, 0, BUF_LEN);
50
51 /* Read the string that was written by the parent */
52 if (fgets(szBuf, BUF_LEN, stdin) == NULL)
53 {
54 return EXIT_ERR_CODE1;
55 }
56
57 /* Write the string out to the stdout & stderr pipes */
58 if (fputs(szBuf, stdout) == EOF
59 || fputs(szBuf, stderr) == EOF)
60 {
61 return EXIT_ERR_CODE2;
62 }
63
64 /* The exit code will indicate success or failure */
65 PAL_TerminateEx(iRetCode);
66
67 /* Return special exit code to indicate success or failure */
68 return iRetCode;
69}
70