| 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: createprocessw/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 | #define UNICODE |
| 21 | #include <palsuite.h> |
| 22 | #include "test2.h" |
| 23 | |
| 24 | |
| 25 | int __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 | WCHAR *swzParam1, *swzParam2, *swzParam3 = NULL; |
| 31 | |
| 32 | |
| 33 | if(0 != (PAL_Initialize(argc, argv))) |
| 34 | { |
| 35 | return FAIL; |
| 36 | } |
| 37 | if (argc != 4) |
| 38 | { |
| 39 | return EXIT_ERR_CODE3; |
| 40 | } |
| 41 | |
| 42 | swzParam1 = convert(argv[1]); |
| 43 | swzParam2 = convert(argv[2]); |
| 44 | swzParam3 = convert(argv[3]); |
| 45 | |
| 46 | if (wcscmp(swzParam1, szArg1) != 0 |
| 47 | || wcscmp(swzParam2, szArg2) != 0 |
| 48 | || wcscmp(swzParam3, szArg3) != 0) |
| 49 | { |
| 50 | return EXIT_ERR_CODE4; |
| 51 | } |
| 52 | |
| 53 | free(swzParam1); |
| 54 | free(swzParam2); |
| 55 | free(swzParam3); |
| 56 | |
| 57 | memset(szBuf, 0, BUF_LEN); |
| 58 | |
| 59 | /* Read the string that was written by the parent */ |
| 60 | if (fgets(szBuf, BUF_LEN, stdin) == NULL) |
| 61 | { |
| 62 | return EXIT_ERR_CODE1; |
| 63 | } |
| 64 | |
| 65 | |
| 66 | /* Write the string out to the stdout & stderr pipes */ |
| 67 | if (fputs(szBuf, stdout) == EOF |
| 68 | || fputs(szBuf, stderr) == EOF) |
| 69 | { |
| 70 | return EXIT_ERR_CODE2; |
| 71 | } |
| 72 | |
| 73 | /* The exit code will indicate success or failure */ |
| 74 | PAL_TerminateEx(iRetCode); |
| 75 | |
| 76 | /* Return special exit code to indicate success or failure */ |
| 77 | return iRetCode; |
| 78 | } |
| 79 | |