1 /*=============================================================================|
2 |  PROJECT SNAP7                                                         1.3.0 |
3 |==============================================================================|
4 |  Copyright (C) 2013, 2015 Davide Nardella                                    |
5 |  All rights reserved.                                                        |
6 |==============================================================================|
7 |  SNAP7 is free software: you can redistribute it and/or modify               |
8 |  it under the terms of the Lesser GNU General Public License as published by |
9 |  the Free Software Foundation, either version 3 of the License, or           |
10 |  (at your option) any later version.                                         |
11 |                                                                              |
12 |  It means that you can distribute your commercial software linked with       |
13 |  SNAP7 without the requirement to distribute the source code of your         |
14 |  application and without the requirement that your application be itself     |
15 |  distributed under LGPL.                                                     |
16 |                                                                              |
17 |  SNAP7 is distributed in the hope that it will be useful,                    |
18 |  but WITHOUT ANY WARRANTY; without even the implied warranty of              |
19 |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
20 |  Lesser GNU General Public License for more details.                         |
21 |                                                                              |
22 |  You should have received a copy of the GNU General Public License and a     |
23 |  copy of Lesser GNU General Public License along with Snap7.                 |
24 |  If not, see  http://www.gnu.org/licenses/                                   |
25 |=============================================================================*/
26 #ifndef snap_platform_h
27 #define snap_platform_h
28 //---------------------------------------------------------------------------
29 #if defined (_WIN32)|| defined(_WIN64)|| defined(__WIN32__) || defined(__WINDOWS__)
30 # define OS_WINDOWS
31 #endif
32 
33 // Visual Studio needs this to use the correct time_t size
34 #if defined (_WIN32) && !defined(_WIN64)
35   // # define _USE_32BIT_TIME_T
36 #endif
37 
38 // Linux, BSD and Solaris define "unix", OSX doesn't, even though it derives from BSD
39 #if defined(unix) || defined(__unix__) || defined(__unix)
40 # define PLATFORM_UNIX
41 #endif
42 
43 #if BSD>=0
44 # define OS_BSD
45 #endif
46 
47 #if __APPLE__
48 # define OS_OSX
49 #endif
50 
51 #if defined(__SVR4) || defined(__svr4__)
52 # define OS_SOLARIS
53 // Thanks to Rolf Stalder now it's possible to use pthreads also for Solaris
54 // In any case the Solaris native threads model is still present and can be
55 // used uncommenting the #define line below.
56 # undef OS_SOLARIS_NATIVE_THREADS
57 // # define OS_SOLARIS_NATIVE_THREADS
58 #endif
59 
60 #if defined(PLATFORM_UNIX)
61 # include <unistd.h>
62 # include <sys/param.h>
63 # if defined(_POSIX_VERSION)
64 #   define POSIX
65 # endif
66 #endif
67 
68 #ifdef OS_OSX
69 # include <unistd.h>
70 #endif
71 
72 #if (!defined (OS_WINDOWS)) && (!defined(PLATFORM_UNIX)) && (!defined(OS_BSD)) && (!defined(OS_OSX))
73 # error platform still unsupported (please add it yourself and report ;-)
74 #endif
75 
76 // Visual C++ not C99 compliant (VS2008--)
77 #ifdef _MSC_VER
78 # if _MSC_VER >= 1600
79 #  include <stdint.h>  // VS2010++ have it
80 # else
81    typedef signed __int8     int8_t;
82    typedef signed __int16    int16_t;
83    typedef signed __int32    int32_t;
84    typedef signed __int64    int64_t;
85    typedef unsigned __int8   uint8_t;
86    typedef unsigned __int16  uint16_t;
87    typedef unsigned __int32  uint32_t;
88    typedef unsigned __int64  uint64_t;
89    #ifdef _WIN64
90      typedef unsigned __int64  uintptr_t;
91    #else
92      typedef unsigned __int32  uintptr_t;
93    #endif
94 # endif
95 #else
96 # include <stdint.h>
97 #endif
98 
99 #include <time.h>
100 #include <cstring>
101 #include <stdlib.h>
102 
103 #ifdef OS_WINDOWS
104 # define WIN32_LEAN_AND_MEAN
105 # include <windows.h>
106 # include <winsock2.h>
107 # include <mmsystem.h>
108 #endif
109 
110 #ifdef OS_SOLARIS
111 # include <sys/filio.h>
112 # include <cstdlib>
113 # include <string.h>
114 #endif
115 
116 #if defined(PLATFORM_UNIX) || defined(OS_OSX)
117 # include <errno.h>
118 # include <sys/time.h>
119 # include <sys/socket.h>
120 # include <arpa/inet.h>
121 # include <netinet/tcp.h>
122 # include <netinet/in.h>
123 # include <sys/ioctl.h>
124 #endif
125 
126 #ifdef OS_WINDOWS
127 # define EXPORTSPEC extern "C" __declspec ( dllexport )
128 # define S7API __stdcall
129 #else
130 # define EXPORTSPEC extern "C"
131 # define S7API
132 #endif
133 
134 // Exact length types regardless of platform/processor
135 // We absolute need of them, all structs have an exact size that
136 // must be the same across the processor used 32/64 bit
137 
138 // *Use them* if you change/expand the code and avoid long, u_long and so on...
139 
140 typedef uint8_t    byte;
141 typedef uint16_t   word;
142 typedef uint32_t   longword;
143 typedef byte       *pbyte;
144 typedef word       *pword;
145 typedef uintptr_t  snap_obj; // multi platform/processor object reference
146 
147 #ifndef OS_WINDOWS
148 # define INFINITE  0XFFFFFFFF
149 #endif
150 
151 
152 #endif // snap_platform_h
153