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