| 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: test2.c |
| 8 | ** |
| 9 | ** Purpose: Test that errno is 'per-thread' as noted in the documentation. |
| 10 | ** |
| 11 | ** |
| 12 | **==========================================================================*/ |
| 13 | |
| 14 | #include <palsuite.h> |
| 15 | |
| 16 | /* |
| 17 | This thread function just checks that errno is initially 0 and then sets |
| 18 | it to a new value before returning. |
| 19 | */ |
| 20 | DWORD PALAPI ThreadFunc( LPVOID lpParam ) |
| 21 | { |
| 22 | |
| 23 | if(errno != 0) |
| 24 | { |
| 25 | *((DWORD*)lpParam) = 1; |
| 26 | } |
| 27 | |
| 28 | errno = 20; |
| 29 | |
| 30 | return 0; |
| 31 | } |
| 32 | |
| 33 | |
| 34 | int __cdecl main(int argc, char *argv[]) |
| 35 | { |
| 36 | DWORD dwThreadId, dwThrdParam = 0; |
| 37 | HANDLE hThread; |
| 38 | |
| 39 | |
| 40 | if (PAL_Initialize(argc, argv)) |
| 41 | { |
| 42 | return FAIL; |
| 43 | } |
| 44 | |
| 45 | /* Set errno to a value within this thread */ |
| 46 | |
| 47 | errno = 50; |
| 48 | |
| 49 | hThread = CreateThread(NULL, 0, ThreadFunc, &dwThrdParam, 0, &dwThreadId); |
| 50 | |
| 51 | if (hThread == NULL) |
| 52 | { |
| 53 | Fail("ERROR: CreateThread failed to create a thread. " |
| 54 | "GetLastError() returned %d.\n" ,GetLastError()); |
| 55 | } |
| 56 | |
| 57 | WaitForSingleObject(hThread, INFINITE); |
| 58 | |
| 59 | /* This checks the result of calling the thread */ |
| 60 | if(dwThrdParam) |
| 61 | { |
| 62 | Fail("ERROR: errno was not set to 0 in the new thread. Each " |
| 63 | "thread should have its own value for errno.\n" ); |
| 64 | } |
| 65 | |
| 66 | /* Check to make sure errno is still set to 50 */ |
| 67 | if(errno != 50) |
| 68 | { |
| 69 | Fail("ERROR: errno should be 50 in the main thread, even though " |
| 70 | "it was set to 20 in another thread. Currently it is %d.\n" , |
| 71 | errno); |
| 72 | } |
| 73 | |
| 74 | PAL_Terminate(); |
| 75 | return PASS; |
| 76 | } |
| 77 | |