| RSA BSAFE Cert-C Micro Edition |
The power of PKI for the smallest of devices |
00001 /* $Id: r_com.h,v 1.56 2002/11/22 02:20:48 zsethna Exp $ */
00002 /*
00003 * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved.
00004 *
00005 * This work contains proprietary information of RSA Security.
00006 * Distribution is limited to authorized licensees of RSA
00007 * Security. Any unauthorized reproduction, distribution or
00008 * modification of this work is strictly prohibited.
00009 *
00010 */
00011 /**
00012 * @file r_com.h
00013 * This file contains the common library prototypes, defines and structures.
00014 */
00015 #ifndef HEADER_COMMON_R_COM_H
00016 #define HEADER_COMMON_R_COM_H
00017
00018 #ifdef __cplusplus
00019 extern "C" {
00020 #endif
00021
00022 /**
00023 * The define for identifying the availability of library header
00024 * <tt>stdio.h</tt>.
00025 */
00026 #ifndef NO_STDIO_H
00027 #include <stdio.h>
00028 #endif
00029
00030 #include <stdlib.h>
00031 #include <string.h>
00032 #include <errno.h>
00033
00034 #if !defined(WIN32) && !defined(UNDER_PALMOS)
00035 /**
00036 * The define for identifying the availability of library header
00037 * <tt>unistd.h</tt>.
00038 */
00039 #ifndef NO_UNISTD_H
00040 #include <unistd.h>
00041 #endif /* NO_UNISTD_H */
00042 #endif
00043
00044 #if defined(WIN32) || defined(MSDOS)
00045 #ifndef UNDER_CE
00046 #include <io.h>
00047 #include <fcntl.h>
00048 #endif /* !UNDER_CE */
00049 #endif /* WIN32 || MSDOS */
00050
00051 /**
00052 * The define for identifying the availability of library header
00053 * <tt>time.h</tt>.
00054 */
00055 #ifndef NO_TIME_H
00056 #include<time.h>
00057 #endif
00058
00059 /*
00060 * Portability code for sleep function, use Sleep instead of sleep.
00061 */
00062 #include "r_sleep.h"
00063
00064 /* Provide the current version of the library */
00065 /**
00066 * Indicates the common library revision number.
00067 */
00068 #define RCOM_VERSION_NUMBER 0x2300
00069
00070 /* Include the define values for the standard error codes */
00071 #include "r_error.h"
00072
00073 #if defined(WINDOWS) || defined(WIN32)
00074 #include <windows.h>
00075 /**
00076 * @fn int R_os_get_last_sys_error()
00077 *
00078 * Retrieves the last system error that occurred in the application.
00079 *
00080 * @return The last system error.
00081 */
00082 #define R_os_get_last_sys_error() GetLastError()
00083 /**
00084 * @fn void R_os_clear_sys_error()
00085 *
00086 * Resets the last system error that occurred in the application.
00087 */
00088 #define R_os_clear_sys_error() SetLastError(0)
00089 #else
00090 /**
00091 * @fn int R_os_get_last_sys_error()
00092 *
00093 * Retrieves the last system error that occurred in the application.
00094 *
00095 * @return The last system error.
00096 */
00097 #define R_os_get_last_sys_error() errno
00098 /**
00099 * @fn void R_os_clear_sys_error()
00100 *
00101 * Resets the last system error that occurred in the application.
00102 */
00103 #define R_os_clear_sys_error() errno=0
00104 #endif
00105
00106 #ifndef R_YIELD_DEFINED
00107 #define R_YIELD_DEFINED
00108 #define R_yield_task(a)
00109 #endif /* !R_YIELD_DEFINED */
00110
00111 /*
00112 * WIN16 requires additional information on the front of functions that
00113 * may cross the application/DLL boundary
00114 *
00115 * Although WIN16 is not a supported platform there is code that used to
00116 * support WIN16 in use and these macros let it continue to operate
00117 * unchanged
00118 */
00119 #if !defined(MS_CALLBACK) || !defined(MS_FAR)
00120 #ifdef WIN16
00121 #define MS_CALLBACK _far _loadds
00122 #define MS_FAR _far
00123 #else /* !WIN16 */
00124 #define MS_CALLBACK
00125 #define MS_FAR
00126 #endif /* WIN16 */
00127 #endif /* !MS_CALLBACK || MS_FAR */
00128
00129 /*
00130 * MS_STATIC is used for items that are placed on the stack normally but
00131 * are safe to make static (i.e. global) in environments with small runtime
00132 * stacks
00133 */
00134 #if defined(WIN16) || defined(MSDOS) || defined(UNDER_PALMOS)
00135 #define MS_STATIC static
00136 #else
00137 #define MS_STATIC
00138 #endif
00139
00140 #if !defined(RCOM_LEAN)
00141
00142 /* include basic platform IO definitions
00143 *
00144 * This file should be included prior to r_mem.h when building
00145 * for vxWorks with the Tornado 2 environment. There is a define
00146 * for Free in vxWorks that is also used in r_mem.h
00147 */
00148
00149 /* r_vxworks.h should be included before r_sock.h to prevent an
00150 * out-of order definition in Tornado 1 (netdb.h is not supplied).
00151 * r_mem.h has to be defined after r_sock.h for VxWorks.
00152 */
00153
00154 #ifdef VXWORKS
00155 #include "r_vxworks.h"
00156 #endif
00157
00158 #if !defined(NO_SOCK)
00159 #include "r_sock.h"
00160 #endif
00161
00162 #include "r_mem.h"
00163
00164 #if defined(PLATFORM_IMODE)
00165 #include "r_imode.h"
00166 #endif /* !PLATFORM_IMODE */
00167
00168 /* include support for asserts */
00169 #include "r_assert.h"
00170
00171 /* include the endian macros */
00172 #include "r_endian.h"
00173
00174 /* include the locking routines and CRYPTO definitions */
00175 #include "r_lock.h"
00176
00177 /* include the surrender functions */
00178 #include "r_surr.h"
00179
00180 #endif /* !defined(RCOM_LEAN) */
00181
00182 #ifndef Memcpy
00183 /**
00184 * Transparently maps the arguments for the system function <tt>memcpy</tt>
00185 * or equivalent so it is platform-independent.
00186 */
00187 #define Memcpy memcpy
00188 #endif
00189
00190 #ifndef Memmove
00191 /**
00192 * Transparently maps the arguments for the system function <tt>memmove</tt>
00193 * or equivalent so it is platform-independent.
00194 */
00195 #define Memmove memmove
00196 #endif
00197
00198 #ifndef Memset
00199 /**
00200 * Transparently maps the arguments for the system function <tt>memset</tt>
00201 * or equivalent so it is platform-independent.
00202 */
00203 #define Memset memset
00204 #endif
00205
00206 #ifndef Memcmp
00207 /**
00208 * Transparently maps the arguments for the system function <tt>memcmp</tt>
00209 * or equivalent so it is platform-independent.
00210 */
00211 #define Memcmp memcmp
00212 #endif
00213
00214 #ifndef Strcmp
00215 /**
00216 * Transparently maps the arguments for the system function <tt>strcmp</tt>
00217 * or equivalent so it is platform-independent.
00218 */
00219 #define Strcmp strcmp
00220 #endif
00221
00222 #ifndef Strncmp
00223 /**
00224 * Transparently maps the arguments for the system function <tt>strncmp</tt>
00225 * or equivalent so it is platform-independent.
00226 */
00227 #define Strncmp strncmp
00228 #endif
00229
00230 #ifndef Strlen
00231 /**
00232 * Transparently maps the arguments for the system function <tt>strlen</tt>
00233 * or equivalent so it is platform-independent.
00234 */
00235 #define Strlen strlen
00236 #endif
00237
00238 #ifndef Strcpy
00239 /**
00240 * Transparently maps the arguments for the system function <tt>strcpy</tt>
00241 * or equivalent so it is platform-independent.
00242 */
00243 #define Strcpy strcpy
00244 #endif
00245
00246 #ifndef Strncpy
00247 /**
00248 * Transparently maps the arguments for the system function <tt>strncpy</tt>
00249 * or equivalent so it is platform-independent.
00250 */
00251 #define Strncpy strncpy
00252 #endif
00253
00254 #ifndef Strcat
00255 /**
00256 * Transparently maps the arguments for the system function <tt>strcat</tt>
00257 * or equivalent so it is platform-independent.
00258 */
00259 #define Strcat strcat
00260 #endif
00261
00262 #ifndef Qsort
00263 /**
00264 * Transparently maps the arguments for the system function <tt>qsort</tt>
00265 * or equivalent so it is platform-independent.
00266 */
00267 #define Qsort(a,b,c,d) \
00268 qsort((void *)(a),(size_t)(b),(size_t)(c),(d))
00269 #endif
00270
00271 #ifndef Strtol
00272 /**
00273 * Transparently maps the arguments for the system function <tt>strtol</tt>
00274 * or equivalent so it is platform-independent.
00275 */
00276 #define Strtol strtol
00277 #endif
00278
00279 #ifndef Strchr
00280 /**
00281 * Transparently maps the arguments for the system function <tt>strtchr</tt>
00282 * or equivalent so it is platform-independent.
00283 */
00284 #define Strchr strchr
00285 #endif
00286
00287 #ifndef Strtoul
00288 /**
00289 * Transparently maps the arguments for the system function <tt>strtoul</tt>
00290 * or equivalent so it is platform-independent.
00291 */
00292 #define Strtoul strtoul
00293 #endif
00294
00295 #ifndef Bsearch
00296 /**
00297 * Transparently maps the arguments for the system function <tt>bsearch</tt>
00298 * or equivalent so it is platform-independent.
00299 */
00300 #define Bsearch(a,b,c,d,e) \
00301 bsearch((void *)(a),(void *)(b),(size_t)(c),(size_t)(d),(e))
00302 #endif
00303
00304 #ifndef Remove
00305 /**
00306 * Transparently maps the arguments for the system function <tt>remove</tt>
00307 * or equivalent so it is platform-independent.
00308 */
00309 #define Remove remove
00310 #endif
00311
00312 #ifndef Isdigit
00313 #ifndef NO_ISDIGIT
00314 #include <ctype.h>
00315 /**
00316 * Transparently maps the arguments for the system function <tt>isdigit</tt>
00317 * or equivalent so it is platform-independent.
00318 */
00319 #define Isdigit isdigit
00320 #else
00321 #define Isdigit(a) (a >= '0' && a <= '9')
00322 #endif
00323 #endif
00324
00325 /* Common/shared structure definitions */
00326 /**
00327 * This structure is used to hold generic data.
00328 */
00329 typedef struct r_item_st
00330 {
00331 /**
00332 * The length of the data array.
00333 */
00334 unsigned int len;
00335
00336 /**
00337 * The data array.
00338 */
00339 unsigned char *data;
00340 } R_ITEM;
00341
00342 /**
00343 * This structure is used to hold generic data marked with a unique type.
00344 */
00345 typedef struct r_titem_st
00346 {
00347 /**
00348 * The type of the data stored in the array.
00349 */
00350 unsigned int type;
00351
00352 /**
00353 * The length of the data array.
00354 */
00355 unsigned int len;
00356
00357 /**
00358 * The data array.
00359 */
00360 unsigned char *data;
00361 } R_TITEM;
00362
00363 /* Common/shared string types */
00364
00365 /**
00366 *
00367 * The define for UTF-8 encoded Unicode characters.
00368 *
00369 * @note The ASCII character set is a subset of UTF-8.
00370 */
00371 #define R_UTF8 char *
00372
00373 #include <limits.h>
00374 #if (defined(LONG_BIT) && (LONG_BIT == 32)) || \
00375 (defined(LONG_MAX) && (LONG_MAX == 2147483647))
00376 /**
00377 * The define for accurately typing 32-bit integers transparently.
00378 */
00379 #define R_INT32 long
00380 /**
00381 * The define for accurately typing 32-bit unsigned integers transparently.
00382 */
00383 #define R_UINT32 unsigned long
00384 #elif (defined(INT_BIT) && (INT_BIT == 32)) || \
00385 (defined(INT_MAX) && (INT_MAX == 2147483647))
00386 #define R_INT32 int
00387 #define R_UINT32 unsigned int
00388 #endif
00389
00390 /**
00391 * The define for accurately typing 16-bit integers transparently.
00392 */
00393 #define R_INT16 short
00394 /**
00395 * The define for accurately typing 16-bit unsigned integers transparently.
00396 */
00397 #define R_UINT16 unsigned short
00398
00399 #ifndef R_INT32
00400 COMPILE ERROR = Cannot find a 32 bit data type for this platform;
00401 #endif
00402
00403 /* When using the Test Framework the <i>main</i> must be replaced with the
00404 * Test Framework <i>main</i> which sets up the Test Framework. As r_com.h
00405 * should be included in all unit tests, system tests, and samples, add
00406 * platform specific definitions of <i>main</i> here.
00407 *
00408 * @note To override TEST_FRAMEWORK use OVERRIDE_TEST_FRAMEWORK. This currently
00409 * only available on a per file basis as the build system does not support
00410 * #defines on a per directory basis. The use of this negate all #defines
00411 * triggered by TEST_FRAMEWORK.
00412 *
00413 */
00414
00415 #ifdef TEST_FRAMEWORK
00416 #ifndef OVERRIDE_TEST_FRAMEWORK
00417 #if defined(PLATFORM_SOLARIS) || defined(PLATFORM_LINUX) || \
00418 (defined(PLATFORM_WINDOWS) && !defined(UNDER_CE)) || defined(PLATFORM_EPOC)
00419 #include "teremote_comms.h"
00420 #include "te_override.h"
00421 #endif /* platform ids */
00422 #endif /* OVERRIDE_TEST_FRAMEWORK */
00423 #endif /* TEST_FRAMEWORK */
00424
00425 #ifdef __cplusplus
00426 }
00427 #endif
00428
00429 #ifndef EVAL_CHECK_DATE
00430 #define EVAL_CHECK_DATE()
00431 #endif
00432
00433 #endif /* HEADER_COMMON_R_COM_H */
00434