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