Pyrogenesis  trunk
wposix.h
Go to the documentation of this file.
1 /* Copyright (c) 2010 Wildfire Games
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining
4  * a copy of this software and associated documentation files (the
5  * "Software"), to deal in the Software without restriction, including
6  * without limitation the rights to use, copy, modify, merge, publish,
7  * distribute, sublicense, and/or sell copies of the Software, and to
8  * permit persons to whom the Software is furnished to do so, subject to
9  * the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 /*
24  * emulate a subset of POSIX on Win32.
25  */
26 
27 #ifndef INCLUDED_WPOSIX
28 #define INCLUDED_WPOSIX
29 
30 /**
31  * rationale: the Windows headers declare many POSIX functions (e.g. read).
32  * unfortunately, these are often slightly incorrect (size_t vs. size_t).
33  * to avert trouble in user code caused by these differences, we declare
34  * all functions ourselves according to SUSv3 and do not use the headers.
35  *
36  * however, it does not end there. some other libraries (e.g. wxWidgets)
37  * will want to pull in these headers, which would conflict with our
38  * declarations. also, our implementation uses the actual CRT code,
39  * so we want those functions (e.g. _read) to be declared correctly even
40  * if switching compiler/CRT version.
41  *
42  * how can these conflicting requirements be reconciled? our headers \#include
43  * "no_crt_posix.h" to \#define the CRT headers' include guards and thus
44  * prevent them from declaring anything. the implementation files \#include
45  * "crt_posix.h", which pulls in the CRT headers (even if "no_crt_posix.h"
46  * was previously included, e.g. in the PCH). note that the CRT headers
47  * would still cause conflicts with the POSIX function declarations,
48  * but we are able to prevent this via __STDC__.
49  **/
50 
51 //
52 // <stdlib.h>
53 //
54 
55 LIB_API int setenv(const char* envname, const char* envval, int overwrite);
56 
57 
58 //
59 // <math.h>
60 //
61 
62 // (missing on MSVC)
63 #ifndef M_PI
64 #define M_PI 3.14159265358979323846
65 #endif
66 #ifndef M_PI_2
67 #define M_PI_2 1.57079632679489661923
68 #endif
69 #ifndef INFINITY
70 #define INFINITY (std::numeric_limits<float>::infinity())
71 #endif
72 #ifndef NAN
73 #define NAN (std::numeric_limits<float>::quiet_NaN())
74 #endif
75 
76 #endif // #ifndef INCLUDED_WPOSIX
LIB_API int setenv(const char *envname, const char *envval, int overwrite)
rationale: the Windows headers declare many POSIX functions (e.g.
Definition: wposix.cpp:34