summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/threading/CreateProcessW/test2/childprocess.c
blob: b4ab9366d9401e8422c1b233532bfd14517d40ac (plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

/*============================================================
**
** Source: createprocessw/test2/childprocess.c
**
** Purpose: This child process reads a string from stdin
**          and writes it out to stdout & stderr
**
** Dependencies: memset
**               fgets
**               gputs
** 

**
**=========================================================*/

#define UNICODE
#include <palsuite.h>
#include "test2.h"


int __cdecl main( int argc, char **argv ) 
{
    int iRetCode = EXIT_OK_CODE; /* preset exit code to OK */
    char szBuf[BUF_LEN];

    WCHAR *swzParam1, *swzParam2, *swzParam3 = NULL;


    if(0 != (PAL_Initialize(argc, argv)))
    {
        return FAIL;
    }
    if (argc != 4)
    {
        return EXIT_ERR_CODE3;
    }

    swzParam1 = convert(argv[1]);
    swzParam2 = convert(argv[2]);
    swzParam3 = convert(argv[3]);

    if (wcscmp(swzParam1, szArg1) != 0
        || wcscmp(swzParam2, szArg2) != 0
        || wcscmp(swzParam3, szArg3) != 0)
    {
        return EXIT_ERR_CODE4;
    }

    free(swzParam1);
    free(swzParam2);
    free(swzParam3);

    memset(szBuf, 0, BUF_LEN);

    /* Read the string that was written by the parent */
    if (fgets(szBuf, BUF_LEN, stdin) == NULL)
    {
        return EXIT_ERR_CODE1;
    }


    /* Write the string out to the stdout & stderr pipes */
    if (fputs(szBuf, stdout) == EOF
        || fputs(szBuf, stderr) == EOF)
    {
        return EXIT_ERR_CODE2;
    }

    /* The exit code will indicate success or failure */
    PAL_TerminateEx(iRetCode);

    /* Return special exit code to indicate success or failure */
    return iRetCode;
}