[wasm][debugger][test] Change DateTime format test (#42136)
[platform/upstream/dotnet/runtime.git] / src / coreclr / src / pal / tests / palsuite / threading / CreateProcessA / test1 / childProcess.cpp
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
4 /*============================================================
5 **
6 ** Source: CreateProcessA/test1/childprocess.c
7 **
8 ** Purpose: Test to ensure CreateProcessA starts a new process.  This test 
9 ** launches a child process, and examines a file written by the child.
10 ** This code is the child code.
11 **
12 ** Dependencies: GetCurrentDirectory
13 **               strlen
14 **               fopen
15 **               fclose
16 **               fprintf
17 ** 
18
19 **
20 **=========================================================*/
21
22 #include <palsuite.h>
23
24 const char *szCommonFileA = "childdata.tmp";
25
26 const char *szPathDelimA = "\\";
27
28 const char *szCommonStringA = "058d2d057111a313aa82401c2e856002\0";
29
30 /*
31  * Take two wide strings representing file and directory names
32  * (dirName, fileName), join the strings with the appropriate path
33  * delimiter and populate a wide character buffer (absPathName) with
34  * the resulting string.
35  *
36  * Returns: The number of wide characters in the resulting string.
37  * 0 is returned on Error.
38  */
39 int 
40 mkAbsoluteFilenameA ( 
41     LPSTR dirName,  
42     DWORD dwDirLength, 
43     LPCSTR fileName, 
44     DWORD dwFileLength,
45     LPSTR absPathName )
46 {
47     extern const char *szPathDelimA;
48
49     DWORD sizeDN, sizeFN, sizeAPN;
50     
51     sizeDN = strlen( dirName );
52     sizeFN = strlen( fileName );
53     sizeAPN = (sizeDN + 1 + sizeFN + 1);
54     
55     /* insure ((dirName + DELIM + fileName + \0) =< _MAX_PATH ) */
56     if ( sizeAPN > _MAX_PATH )
57     {
58         return ( 0 );
59     }
60     
61     strncpy(absPathName, dirName, dwDirLength +1);
62     strncpy(absPathName, szPathDelimA, 2);
63     strncpy(absPathName, fileName, dwFileLength +1);
64     
65     return (sizeAPN);
66   
67
68
69 int __cdecl main( int argc, char **argv ) 
70 {
71
72     static FILE * fp;
73
74     DWORD dwFileLength;
75     DWORD dwDirLength;
76     DWORD dwSize;
77     
78     char szDirNameA[_MAX_DIR];
79     char szAbsPathNameA[_MAX_PATH];
80
81     if(0 != (PAL_Initialize(argc, argv)))
82     {
83         return ( FAIL );
84     }
85
86     dwDirLength = GetCurrentDirectory( _MAX_PATH, szDirNameA );
87
88     if (0 == dwDirLength) 
89     {
90         Fail ("GetCurrentDirectory call failed.  Could not get "
91                 "current working directory\n.  Exiting.\n");
92     }
93
94     dwFileLength = strlen( szCommonFileA );
95
96     dwSize = mkAbsoluteFilenameA( szDirNameA, dwDirLength, szCommonFileA, 
97                                   dwFileLength, szAbsPathNameA );
98
99     if (0 == dwSize)
100     {
101         Fail ("Palsuite Code: mkAbsoluteFilename() call failed.  Could "
102                 "not build absolute path name to file\n.  Exiting.\n");
103     }
104     
105     if ( NULL == ( fp = fopen ( szAbsPathNameA , "w+" ) ) ) 
106     {
107        /* 
108          * A return value of NULL indicates an error condition or an
109          * EOF condition 
110          */
111         Fail ("%s unable to open %s for writing.  Exiting.\n", argv[0]
112               , szAbsPathNameA );
113     }
114
115     if ( 0 >= ( fprintf ( fp, "%s", szCommonStringA )))
116     {
117         Fail("%s unable to write to %s. Exiting.\n", argv[0]
118              , szAbsPathNameA );
119     }
120     
121     if (0 != (fclose ( fp ))) 
122     {
123         Fail ("%s unable to close file %s.  Pid may not be "
124               "written to file. Exiting.\n", argv[0], szAbsPathNameA );
125     }
126
127     PAL_Terminate();
128     return ( PASS );    
129     
130 }