Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Slight clarification of variable names
[simgrid.git] / win32_test_app / src / TErrno.c
1 #include <TErrno.h>
2
3 /* Global variable */
4 static errno_t __errno = E_SUCCESS;
5 static CRITICAL_SECTION errno_cs;
6 static bool errno_cs_initialized = false;
7 static is_last_errno = false;
8
9 void initializeErrno(void)
10 {
11         if(!errno_cs_initialized)
12         {
13                 memset(&errno_cs,0,sizeof(CRITICAL_SECTION)) ;
14                 InitializeCriticalSection(&errno_cs);
15                 errno_cs_initialized = true;
16         }
17 }
18
19 void terminateErrno(void)
20 {
21         if(errno_cs_initialized)
22         {
23                 DeleteCriticalSection(&errno_cs);
24         }
25 }
26
27
28 void setErrno(errno_t e)
29 {
30         EnterCriticalSection(&errno_cs);
31
32     if((E_SUCCESS != e) && !is_last_errno)
33     {
34             __errno = e;
35         is_last_errno = true;
36     }
37         
38    LeaveCriticalSection(&errno_cs);
39 }
40
41 errno_t getErrno(void)
42 {
43         errno_t e;
44         EnterCriticalSection(&errno_cs);
45         e = __errno;
46         LeaveCriticalSection(&errno_cs);
47         
48         return e;
49 }