5 * Copyright 2003, 2004 Porchdog Software, Inc. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without modification,
8 * are permitted provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY PORCHDOG SOFTWARE ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE HOWL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
24 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
25 * OF THE POSSIBILITY OF SUCH DAMAGE.
27 * The views and conclusions contained in the software and documentation are those
28 * of the authors and should not be interpreted as representing official policies,
29 * either expressed or implied, of Porchdog Software, Inc.
39 #if defined(__VXWORKS__)
45 # define sw_snooze(SECS) taskDelay(sysClkRateGet() * SECS)
49 # define WIN32_LEAN_AND_MEAN
50 # define HOWL_API __stdcall
51 # pragma warning(disable:4127)
55 typedef signed char int8_t;
56 typedef unsigned char u_int8_t;
57 typedef signed short int16_t;
58 typedef unsigned short u_int16_t;
59 typedef signed long int32_t;
60 typedef unsigned long u_int32_t;
61 typedef _int64 int64_t;
62 typedef _int64 u_int64_t;
64 # define sw_snooze(SECS) Sleep(SECS * 1000)
69 # if defined(HOWL_KERNEL)
70 # include <howl_config.h>
72 # include <sys/types.h>
76 # define sw_snooze(SECS) sleep(SECS)
82 # define u_int8_t uint8_t
83 # define u_int16_t uint16_t
84 # define u_int32_t uint32_t
85 # define u_int64_t uint64_t
89 typedef void * sw_opaque;
90 typedef void * sw_opaque_t;
91 typedef int8_t sw_int8;
92 typedef u_int8_t sw_uint8;
93 typedef u_int8_t sw_bool;
94 typedef int16_t sw_int16;
95 typedef u_int16_t sw_uint16;
96 typedef int32_t sw_int32;
97 typedef u_int32_t sw_uint32;
98 typedef int64_t sw_int64;
99 typedef u_int64_t sw_uint64;
100 typedef char * sw_string;
101 typedef sw_uint8 * sw_octets;
102 #if !defined(__VXWORKS__) || defined(__cplusplus)
103 typedef const char * sw_const_string;
104 typedef const u_int8_t * sw_const_octets;
106 typedef char * sw_const_string;
107 typedef u_int8_t * sw_const_octets;
109 typedef size_t sw_size_t;
110 typedef int sw_result;
114 /* --------------------------------------------------------
118 * SW_ENDIAN is 0 for big endian platforms, 1
119 * for little endian platforms.
121 * The macro WORDS_BIGENDIAN will be defined
122 * by autoconf. If you are using Howl on
123 * a platform that doesn't have autoconf, define
125 * --------------------------------------------------------
128 #if !defined(SW_ENDIAN)
130 # if WORDS_BIGENDIAN == 1
143 /* --------------------------------------------------------
147 * These macros supports cross platform string functions
148 * for the following OSes
155 * --------------------------------------------------------
162 # define sw_memset(ARG1, ARG2, ARG3) memset((char*) ARG1, ARG2, ARG3)
163 # define sw_memcpy(ARG1, ARG2, ARG3) memmove((char*) ARG1, (char*) ARG2, ARG3)
164 # define sw_memcmp(ARG1, ARG2, ARG3) memcmp((char*) ARG1, ARG2, ARG3)
165 # define sw_strcasecmp(ARG1, ARG2) stricmp(ARG1, ARG2)
166 # define sw_strncasecmp(ARG1, ARG2) strnicmp(ARG1, ARG2)
167 # define sw_strcat(ARG1, ARG2) strcat(ARG1, ARG2)
168 # define sw_strncat(ARG1, ARG2) strncat(ARG1, ARG2)
169 # define sw_strchr(ARG1, ARG2) strchr(ARG1, ARG2)
170 # define sw_strcmp(ARG1, ARG2) strcmp(ARG1, ARG2)
171 # define sw_strncmp(ARG1, ARG2) strncmp(ARG1, ARG2)
172 # define sw_strcoll(ARG1, ARG2) strcoll(ARG1, ARG2)
173 # define sw_strcpy(ARG1, ARG2) (ARG2) ? strcpy(ARG1, ARG2) : strcpy(ARG1, "")
174 # define sw_strncpy(ARG1, ARG2, N) (ARG2) ? strncpy(ARG1, ARG2, N) : strcpy(ARG1, "")
175 # define sw_strcspn(ARG1, ARG2) strcspn(ARG1, ARG2)
176 # define sw_strlen(ARG1) strlen(ARG1)
177 # define sw_strstr(ARG1, ARG2) strstr(ARG1, ARG2)
178 # define sw_strtok_r(ARG1, ARG2, ARG3) strtok_r(ARG1, ARG2, ARG3)
180 #elif defined(__VXWORKS__)
186 sw_const_string arg1,
187 sw_const_string arg2);
191 sw_const_string arg1,
192 sw_const_string arg2,
198 sw_const_string arg2,
201 # define sw_memset(ARG1, ARG2, ARG3) memset((char*) ARG1, ARG2, ARG3)
202 # define sw_memcpy(ARG1, ARG2, ARG3) memcpy((char*) ARG1, (char*) ARG2, ARG3)
203 # define sw_memcmp(ARG1, ARG2, ARG3) memcmp((char*) ARG1, ARG2, ARG3)
204 # define sw_strcat(ARG1, ARG2) strcat(ARG1, ARG2)
205 # define sw_strncat(ARG1, ARG2) strncat(ARG1, ARG2)
206 # define sw_strchr(ARG1, ARG2) strchr(ARG1, ARG2)
207 # define sw_strcmp(ARG1, ARG2) strcmp(ARG1, ARG2)
208 # define sw_strncmp(ARG1, ARG2) strncmp(ARG1, ARG2)
209 # define sw_strcoll(ARG1, ARG2) strcoll(ARG1, ARG2)
210 # define sw_strcpy(ARG1, ARG2) ARG2 ? strcpy(ARG1, ARG2) : strcpy(ARG1, "")
211 # define sw_strncpy(ARG1, ARG2, N) ARG2 ? strncpy(ARG1, ARG2, N) : strcpy(ARG1, "")
212 # define sw_strcspn(ARG1, ARG2) strcspn(ARG1, ARG2)
213 # define sw_strlen(ARG1) strlen(ARG1)
214 # define sw_strstr(ARG1, ARG2) strstr(ARG1, ARG2)
216 #elif defined(__PALMOS__)
218 # include <StringMgr.h>
220 # define sw_strcasecmp(ARG1, ARG2) strcasecmp(ARG1, ARG2)
221 # define sw_strncasecmp(ARG1, ARG2) strncasecmp(ARG1, ARG2)
222 # define sw_strcat(ARG1, ARG2) StrCat(ARG1, ARG2)
223 # define sw_strncat(ARG1, ARG2) StrNCat(ARG1, ARG2)
224 # define sw_strchr(ARG1, ARG2) StrChr(ARG1, ARG2)
225 # define sw_strcmp(ARG1, ARG2) StrCampare(ARG1, ARG2)
226 # define sw_strncmp(ARG1, ARG2) StrNCompare(ARG1, ARG2)
227 # define sw_strcoll(ARG1, ARG2) strcoll(ARG1, ARG2)
228 # define sw_strcpy(ARG1, ARG2) ARG2 ? StrCopy(ARG1, ARG2) : StrCopy(ARG1, "")
229 # define sw_strncpy(ARG1, ARG2, N) ARG2 ? StrNCopy(ARG1, ARG2, N) : StrCopy(ARG1, "")
230 # define sw_strcspn(ARG1, ARG2) strcspn(ARG1, ARG2)
231 # define sw_strlen(ARG1) StrLen(ARG1)
232 # define sw_strstr(ARG1, ARG2) strstr(ARG1, ARG2)
233 # define sw_strtok_r(ARG1, ARG2, ARG3) strtok_r(ARG1, ARG2, ARG3)
239 # if defined(__Lynx__)
240 char * strchr(char*, int);
243 # define sw_memset(ARG1, ARG2, ARG3) memset((char*) ARG1, ARG2, ARG3)
244 # define sw_memcpy(ARG1, ARG2, ARG3) memcpy((char*) ARG1, (char*) ARG2, ARG3)
245 # define sw_memcmp(ARG1, ARG2, ARG3) memcmp((char*) ARG1, ARG2, ARG3)
246 # define sw_strcasecmp(ARG1, ARG2) strcasecmp(ARG1, ARG2)
247 # define sw_strncasecmp(ARG1, ARG2) strncasecmp(ARG1, ARG2)
248 # define sw_strcat(ARG1, ARG2) strcat(ARG1, ARG2)
249 # define sw_strncat(ARG1, ARG2) strncat(ARG1, ARG2)
250 # define sw_strchr(ARG1, ARG2) strchr(ARG1, ARG2)
251 # define sw_strcmp(ARG1, ARG2) strcmp(ARG1, ARG2)
252 # define sw_strncmp(ARG1, ARG2) strncmp(ARG1, ARG2)
253 # define sw_strcoll(ARG1, ARG2) strcoll(ARG1, ARG2)
254 # define sw_strcpy(ARG1, ARG2) ARG2 ? strcpy(ARG1, ARG2) : strcpy(ARG1, "")
255 # define sw_strncpy(ARG1, ARG2, N) ARG2 ? strncpy(ARG1, ARG2, N) : strcpy(ARG1, "")
256 # define sw_strcspn(ARG1, ARG2) strcspn(ARG1, ARG2)
257 # define sw_strlen(ARG1) strlen(ARG1)
258 # define sw_strstr(ARG1, ARG2) strstr(ARG1, ARG2)
259 # define sw_strtok_r(ARG1, ARG2, ARG3) strtok_r(ARG1, ARG2, ARG3)
266 sw_const_string str);
269 /* --------------------------------------------------------
273 * These macros support cross platform heap functions.
274 * When compiling with DEBUG, some extra checking is
275 * done which can aid in tracking down heap corruption
278 * --------------------------------------------------------
283 # define sw_malloc(SIZE) malloc(SIZE)
284 # define sw_realloc(MEM,SIZE) realloc(MEM, SIZE)
285 # define sw_free(MEM) if (MEM) free(MEM)
289 # define sw_malloc(SIZE) _sw_debug_malloc(SIZE, __SW_FUNCTION__, __FILE__, __LINE__)
290 # define sw_realloc(MEM,SIZE) _sw_debug_realloc(MEM, SIZE, __SW_FUNCTION__, __FILE__, __LINE__)
291 # define sw_free(MEM) if (MEM) _sw_debug_free(MEM, __SW_FUNCTION__, __FILE__, __LINE__)
299 sw_const_string function,
300 sw_const_string file,
308 sw_const_string function,
309 sw_const_string file,
316 sw_const_string function,
317 sw_const_string file,
322 /* --------------------------------------------------------
326 * These macros and APIs support cross platform socket
327 * calls. I am relying on BSD APIs, but even with those
328 * there are subtle and not so subtle platform differences
330 * --------------------------------------------------------
333 #if defined(__VXWORKS__)
335 # include <vxworks.h>
336 # include <hostLib.h>
337 # include <sockLib.h>
339 # include <inetLib.h>
341 typedef int sw_sockdesc_t;
342 typedef socklen_t sw_socklen_t;
346 # include <winsock2.h>
348 typedef SOCKET sw_sockdesc_t;
349 typedef int sw_socklen_t;
351 # define SW_E_WOULDBLOCK WSAEWOULDBLOCK
352 # define SW_INVALID_SOCKET INVALID_SOCKET
353 # define SW_SOCKET_ERROR SOCKET_ERROR
355 # define sw_close_socket(X) closesocket(X)
365 # include <sys/types.h>
368 # if defined(__Lynx__)
374 # include <sys/socket.h>
378 # include <netinet/in.h>
379 # include <netinet/tcp.h>
381 # include <arpa/inet.h>
384 # include <sys/ioctl.h>
388 typedef sw_int32 sw_sockdesc_t;
389 typedef socklen_t sw_socklen_t;
391 # define SW_E_WOULDBLOCK EWOULDBLOCK
392 # define SW_INVALID_SOCKET -1
393 # define SW_SOCKET_ERROR -1
395 # define sw_close_socket(X) close(X)
400 /* --------------------------------------------------------
404 * This function will print a string rep of a system error
407 * --------------------------------------------------------
415 * Obsolete types and macros.
417 * These are here for backwards compatibility, but will
418 * be removed in the future
420 #define sw_char sw_int8
421 #define sw_uchar sw_uint8
422 #define sw_octet sw_uint8
423 #define sw_short sw_int16
424 #define sw_ushort sw_uint16
425 #define sw_long sw_int32
426 #define sw_ulong sw_uint32
429 #define SW_TRY(EXPR) { sw_result result; if ((result = EXPR) != SW_OKAY) return result; } ((void) 0)
430 #define SW_TRY_GOTO(EXPR) { if ((result = EXPR) != SW_OKAY) goto exit; } ((void) 0)