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** Source : test6.c
7**
8** Purpose: Test for GetEnvironmentVariableA() function
9** Create environment variables that differ only
10** in case and verify that they return the appropriate
11** value on the BSD environment.
12**
13
14**
15===========================================================*/
16
17#include <palsuite.h>
18
19int __cdecl main(int argc, char *argv[])
20{
21
22#if WIN32
23
24 /* Define some buffers needed for the function */
25 char * pResultBuffer = NULL;
26
27 char FirstEnvironmentVariable[] = {"PALTEST"};
28 char FirstEnvironmentValue[] = {"FIRST"};
29 char ModifiedEnvVar[] = {"paltest"};
30
31 DWORD size = 0;
32 BOOL bRc = TRUE;
33
34 /*
35 * Initialize the PAL and return FAILURE if this fails
36 */
37
38 if(0 != (PAL_Initialize(argc, argv)))
39 {
40 return FAIL;
41 }
42
43 /* Set the first environment variable */
44 bRc = SetEnvironmentVariableA(FirstEnvironmentVariable,
45 FirstEnvironmentValue);
46
47 if(!bRc)
48 {
49 Fail("ERROR: SetEnvironmentVariable failed to set a "
50 "proper environment variable with error %u.\n",
51 GetLastError());
52 }
53
54 /* Normal case, PATH should fit into this buffer */
55 size = GetEnvironmentVariableA(ModifiedEnvVar,
56 pResultBuffer,
57 0);
58
59 /* To account for the nul character at the end of the string */
60 size = size + 1;
61
62 pResultBuffer = (char*)malloc(sizeof(char)*size);
63 if ( pResultBuffer == NULL )
64 {
65 Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n");
66 }
67
68 /* Try to retrieve the value of the first environment variable */
69 GetEnvironmentVariableA(ModifiedEnvVar,
70 pResultBuffer,
71 size);
72
73 if ( pResultBuffer == NULL )
74 {
75 free(pResultBuffer);
76 Fail("ERROR: GetEnvironmentVariable failed to return a value "
77 "from a proper environment variable with error %u.\n",
78 GetLastError());
79 }
80
81 /* Compare the strings to see that the correct variable was returned */
82 if(strcmp(pResultBuffer,FirstEnvironmentValue) != 0)
83 {
84 free(pResultBuffer);
85 Fail("ERROR: The value in the buffer should have been '%s' but "
86 "was really '%s'.\n",FirstEnvironmentValue, pResultBuffer);
87 }
88
89 free(pResultBuffer);
90
91 PAL_Terminate();
92 return PASS;
93
94
95#else
96
97 return PASS;
98#endif
99}
100