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: test3.c |
8 | ** |
9 | ** Purpose: Create an environment variable and try to retrieve |
10 | ** it using the same name but with different case. This |
11 | ** is to show that the Win32 representation of getenv |
12 | ** is case insensitive. |
13 | ** |
14 | ** |
15 | **===================================================================*/ |
16 | |
17 | #include <palsuite.h> |
18 | |
19 | int __cdecl main(int argc, char **argv) |
20 | { |
21 | #if WIN32 |
22 | |
23 | const char* FirstVariable = "PalTestingEnvironmentVariable=The value" ; |
24 | const char* ModifiedName = "PALTESTINGEnvironmentVariable" ; |
25 | const char* FirstVarValue = "The value" ; |
26 | char* result; |
27 | |
28 | |
29 | if (0 != (PAL_Initialize(argc, argv))) |
30 | { |
31 | return FAIL; |
32 | } |
33 | |
34 | /* Use _putenv to set an environment variable. This ensures that the |
35 | variable we're testing on is always present. |
36 | */ |
37 | |
38 | if(_putenv(FirstVariable) != 0) |
39 | { |
40 | Fail("ERROR: _putenv failed to set an environment variable that " |
41 | "getenv will be using for testing.\n" ); |
42 | } |
43 | |
44 | |
45 | /* Call getenv -- ensure it doesn't return NULL and the string it returns |
46 | is the value we set above. Also make sure that each environment variable, |
47 | differing only by case, doesn't affect the return value. |
48 | */ |
49 | |
50 | result = getenv(ModifiedName); |
51 | if(result == NULL) |
52 | { |
53 | Fail("ERROR: The result of getenv on a valid Environment Variable " |
54 | "was NULL, which indicates the environment varaible was not " |
55 | "found.\n" ); |
56 | } |
57 | |
58 | if(strcmp(result, FirstVarValue) != 0) |
59 | { |
60 | Fail("ERROR: The value obtained by getenv() was not equal to the " |
61 | "correct value of the environment variable. The correct " |
62 | "value is '%s' and the function returned '%s'.\n" , |
63 | FirstVarValue, |
64 | result); |
65 | } |
66 | |
67 | |
68 | PAL_Terminate(); |
69 | return PASS; |
70 | |
71 | #else |
72 | return PASS; |
73 | |
74 | #endif |
75 | } |
76 | |