Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Action replayer: don't hardcode the usage of raw contextes
[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     memset(&errno_cs, 0, sizeof(CRITICAL_SECTION));
13     InitializeCriticalSection(&errno_cs);
14     errno_cs_initialized = true;
15   }
16 }
17
18 void terminateErrno(void)
19 {
20   if (errno_cs_initialized) {
21     DeleteCriticalSection(&errno_cs);
22   }
23 }
24
25
26 void setErrno(errno_t e)
27 {
28   EnterCriticalSection(&errno_cs);
29
30   if ((E_SUCCESS != e) && !is_last_errno) {
31     __errno = e;
32     is_last_errno = true;
33   }
34
35   LeaveCriticalSection(&errno_cs);
36 }
37
38 errno_t getErrno(void)
39 {
40   errno_t e;
41   EnterCriticalSection(&errno_cs);
42   e = __errno;
43   LeaveCriticalSection(&errno_cs);
44
45   return e;
46 }