Missing test.
[mono.git] / mono / io-layer / error.c
1 #include <config.h>
2 #include <glib.h>
3 #include <pthread.h>
4
5 #include "mono/io-layer/wapi.h"
6
7 static pthread_key_t error_key;
8 static pthread_once_t error_key_once=PTHREAD_ONCE_INIT;
9
10 static void error_init(void)
11 {
12         pthread_key_create(&error_key, NULL);
13 }
14
15 /**
16  * GetLastError:
17  *
18  * Retrieves the last error that occurred in the calling thread.
19  *
20  * Return value: The error code for the last error that happened on
21  * the calling thread.
22  */
23 guint32 GetLastError(void)
24 {
25         guint32 err;
26         void *errptr;
27         
28         pthread_once(&error_key_once, error_init);
29         errptr=pthread_getspecific(error_key);
30         err=GPOINTER_TO_UINT(errptr);
31         
32         return(err);
33 }
34
35 /**
36  * SetLastError:
37  * @code: The error code.
38  *
39  * Sets the error code in the calling thread.
40  */
41 void SetLastError(guint32 code)
42 {
43         /* Set the thread-local error code */
44         pthread_once(&error_key_once, error_init);
45         pthread_setspecific(error_key, GUINT_TO_POINTER(code));
46 }