]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/net/https/axTLS/ssl/os_port_old.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / net / https / axTLS / ssl / os_port_old.h
1 /*
2  * Copyright (c) 2007, Cameron Rich
3  * 
4  * All rights reserved.
5  * 
6  * Redistribution and use in source and binary forms, with or without 
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright notice, 
10  *   this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright notice, 
12  *   this list of conditions and the following disclaimer in the documentation 
13  *   and/or other materials provided with the distribution.
14  * * Neither the name of the axTLS project nor the names of its contributors 
15  *   may be used to endorse or promote products derived from this software 
16  *   without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 /**
32  * @file os_port.h
33  *
34  * Some stuff to minimise the differences between windows and linux/unix
35  */
36
37 #ifndef HEADER_OS_PORT_H
38 #define HEADER_OS_PORT_H
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 #include "os_int.h"
45 #include <stdio.h>
46
47 #if defined(WIN32)
48 #define STDCALL                 __stdcall
49 #define EXP_FUNC                __declspec(dllexport)
50 #else
51 #define STDCALL
52 #define EXP_FUNC
53 #endif
54
55 #if defined(_WIN32_WCE)
56 #undef WIN32
57 #define WIN32
58 #endif
59
60 #ifdef WIN32
61
62 /* Windows CE stuff */
63 #if defined(_WIN32_WCE)
64 #include <basetsd.h>
65 #define abort()                 exit(1)
66 #else
67 #include <io.h>
68 #include <process.h>
69 #include <sys/timeb.h>
70 #include <fcntl.h>
71 #endif      /* _WIN32_WCE */
72
73 #include <winsock.h>
74 #include <direct.h>
75 #undef getpid
76 #undef open
77 #undef close
78 #undef sleep
79 #undef gettimeofday
80 #undef dup2
81 #undef unlink
82
83 #define SOCKET_READ(A,B,C)      recv(A,B,C,0)
84 #define SOCKET_WRITE(A,B,C)     send(A,B,C,0)
85 #define SOCKET_CLOSE(A)         closesocket(A)
86 #define srandom(A)              srand(A)
87 #define random()                rand()
88 #define getpid()                _getpid()
89 #define snprintf                _snprintf
90 #define open(A,B)               _open(A,B)
91 #define dup2(A,B)               _dup2(A,B)
92 #define unlink(A)               _unlink(A)
93 #define close(A)                _close(A)
94 #define read(A,B,C)             _read(A,B,C)
95 #define write(A,B,C)            _write(A,B,C)
96 #define sleep(A)                Sleep(A*1000)
97 #define usleep(A)               Sleep(A/1000)
98 #define strdup(A)               _strdup(A)
99 #define chroot(A)               _chdir(A)
100 #define chdir(A)                _chdir(A)
101 #define alloca(A)               _alloca(A)
102
103
104 #ifndef lseek
105 #define lseek(A,B,C)            _lseek(A,B,C)
106
107 #endif
108
109 /* This fix gets around a problem where a win32 application on a cygwin xterm
110    doesn't display regular output (until a certain buffer limit) - but it works
111    fine under a normal DOS window. This is a hack to get around the issue - 
112    see http://www.khngai.com/emacs/tty.php  */
113 #define TTY_FLUSH()             if (!_isatty(_fileno(stdout))) fflush(stdout);
114
115 /*
116  * automatically build some library dependencies.
117  */
118 #pragma comment(lib, "WS2_32.lib")
119 #pragma comment(lib, "AdvAPI32.lib")
120
121 typedef int socklen_t;
122
123 EXP_FUNC void STDCALL gettimeofday(struct timeval* t,void* timezone);
124 EXP_FUNC int STDCALL strcasecmp(const char *s1, const char *s2);
125 EXP_FUNC int STDCALL getdomainname(char *buf, int buf_size);
126
127 #else   /* Not Win32 */
128
129 //#include <unistd.h>
130 //#include <pwd.h>
131 //#include <netdb.h>
132 //#include <dirent.h>
133 //#include <fcntl.h>
134 #include <errno.h>
135 //#include <sys/stat.h>
136 #include <time.h>
137 #include <socket.h>
138 //#include <sys/wait.h>
139 #include <netinet/in.h>
140 #include <inet.h>
141
142 #define SOCKET_READ(A,B,C)      read(A,B,C)
143 #define SOCKET_WRITE(A,B,C)     write(A,B,C)
144 #define SOCKET_CLOSE(A)         if (A >= 0) close(A)
145 #define TTY_FLUSH()
146
147 #endif  /* Not Win32 */
148
149 /* some functions to mutate the way these work */
150 #define malloc(A)       ax_malloc(A)
151 #ifndef realloc
152 #define realloc(A,B)    ax_realloc(A,B)
153 #endif
154 #define calloc(A,B)     ax_calloc(A,B)
155
156 EXP_FUNC void * STDCALL ax_malloc(size_t s);
157 EXP_FUNC void * STDCALL ax_realloc(void *y, size_t s);
158 EXP_FUNC void * STDCALL ax_calloc(size_t n, size_t s);
159 EXP_FUNC int STDCALL ax_open(const char *pathname, int flags); 
160
161 #ifdef CONFIG_PLATFORM_LINUX
162 void exit_now(const char *format, ...) __attribute((noreturn));
163 #else
164 void exit_now(const char *format, ...);
165 #endif
166
167 /* Mutexing definitions */
168 #if defined(CONFIG_SSL_CTX_MUTEXING)
169 #if defined(WIN32)
170 #define SSL_CTX_MUTEX_TYPE          HANDLE
171 #define SSL_CTX_MUTEX_INIT(A)       A=CreateMutex(0, FALSE, 0)
172 #define SSL_CTX_MUTEX_DESTROY(A)    CloseHandle(A)
173 #define SSL_CTX_LOCK(A)             WaitForSingleObject(A, INFINITE)
174 #define SSL_CTX_UNLOCK(A)           ReleaseMutex(A)
175 #else 
176 #include <pthread.h>
177 #define SSL_CTX_MUTEX_TYPE          pthread_mutex_t
178 #define SSL_CTX_MUTEX_INIT(A)       pthread_mutex_init(&A, NULL)
179 #define SSL_CTX_MUTEX_DESTROY(A)    pthread_mutex_destroy(&A)
180 #define SSL_CTX_LOCK(A)             pthread_mutex_lock(&A)
181 #define SSL_CTX_UNLOCK(A)           pthread_mutex_unlock(&A)
182 #endif
183 #else   /* no mutexing */
184 #define SSL_CTX_MUTEX_INIT(A)
185 #define SSL_CTX_MUTEX_DESTROY(A)
186 #define SSL_CTX_LOCK(A)
187 #define SSL_CTX_UNLOCK(A)
188 #endif
189
190 #ifdef __cplusplus
191 }
192 #endif
193
194 #endif