RSA BSAFE Micro Edition Suite

Streamlined security for mobile and embedded devices

Search  Print

r_com.h

Go to the documentation of this file.
00001 /* $Id: r_com.h,v 1.71.6.1 2005/09/21 23:21:13 sparki Exp $ */
00002 /*
00003  * Copyright (C) 1998-2004 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  */
00014 #ifndef HEADER_COMMON_R_COM_H
00015 #define HEADER_COMMON_R_COM_H
00016 
00017 #ifdef  __cplusplus
00018 extern "C" {
00019 #endif
00020 
00021 /*
00022  * Platform definitions
00023  */
00024 #include "r_platf.h"
00025 
00030 #ifndef NO_STDIO_H
00031 #include <stdio.h>
00032 #endif
00033 
00034 #ifndef NO_STDLIB_H
00035 #include <stdlib.h>
00036 #endif
00037 #ifndef NO_STRING_H
00038 #include <string.h>
00039 #endif
00040 #ifndef NO_ERRNO_H
00041 #include <errno.h>
00042 #endif
00043 
00044 /*R_CDECL is defined for the calling convention */
00045 #ifndef R_CDECL
00046 #ifdef PLATFORM_WINDOWS
00047 #define R_CDECL __cdecl
00048 #else
00049 #define R_CDECL
00050 #endif   /* PLATFORM_WINDOWS */
00051 #endif   /* R_CDECL */
00052 
00053 #if defined(PLATFORM_LINUX_KERNEL)
00054 /* Includes kernel header files. PLATFORM_LINUX_KERNEL setup doesn't
00055  * include standard include file such as stdio.h  */
00056 #include <linux/types.h>
00057 #include <linux/ctype.h>
00058 #include <linux/config.h>
00059 #include <linux/module.h>
00060 #include <linux/kernel.h>
00061 #include <linux/init.h>
00062 #include <linux/wait.h>
00063 #include <linux/smp_lock.h>
00064 #include <linux/stddef.h>
00065 #include <linux/string.h>
00066 #include <linux/errno.h>
00067 #include <linux/time.h>
00068 #include <linux/slab.h>
00069 #include <asm/unistd.h>
00070 #endif
00071 
00072 
00073 #if !defined(WIN32) && !defined(UNDER_PALMOS)
00074 
00078 #ifndef NO_UNISTD_H
00079 #include <unistd.h>
00080 #endif /* NO_UNISTD_H */
00081 #endif
00082 
00083 #if defined(WIN32) || defined(MSDOS)
00084 #ifndef UNDER_CE
00085 #include <io.h>
00086 #include <fcntl.h>
00087 #endif /* !UNDER_CE */
00088 #endif /* WIN32 || MSDOS */
00089 
00090 /*
00091  * specify the platform specific path and directory delimiters
00092  * (i.e. the separator between elements in the path)
00093  */
00094 #if defined(WIN32) || defined(MSDOS)
00095 #define R_PATH_DELIMITER        ';'
00096 #define R_DIRECTORY_DELIMITER   '\\'
00097 #else /* !(WIN32 || MSDOS) */
00098 #define R_PATH_DELIMITER        ':'
00099 #define R_DIRECTORY_DELIMITER   '/'
00100 #endif /* WIN32 || MSDOS */
00101 
00106 #ifndef NO_TIME_H
00107 #include<time.h>
00108 #endif
00109 
00110 /*
00111  * Portability code for sleep function, use R_sleep instead of sleep.
00112  */
00113 #include "r_sleep.h"
00114 
00115 /* Provide the current version of the library */
00119 #define RCOM_VERSION_NUMBER               0x2300
00120 
00121 /* Include the define values for the standard error codes */
00122 #include "r_error.h"
00123 
00147 #if defined(WINDOWS) || defined(WIN32)
00148 #if defined(WIN32_DRIVER)
00149 #include <ntddk.h>
00150 #else /* WIN32_DRIVER */
00151 #include <windows.h>
00152 #endif /* WIN32_DRIVER */
00153 
00161 #define R_os_get_last_sys_error()          GetLastError()
00162 
00168 #define R_os_clear_sys_error()             SetLastError(0)
00169 #else
00170 #if defined(PLATFORM_LINUX_KERNEL)
00171 
00179 #define R_os_get_last_sys_error()
00180 
00187 #define R_os_clear_sys_error()
00188 #else
00189 
00197 #define R_os_get_last_sys_error()          errno
00198 
00204 #define R_os_clear_sys_error()             errno=0
00205 #endif
00206 
00207 #endif
00208 
00209 #ifndef R_YIELD_DEFINED
00210 #define R_YIELD_DEFINED
00211 #define R_yield_task(a)
00212 #endif /* !R_YIELD_DEFINED */
00213 
00214 /*
00215  * WIN16 requires additional information on the front of functions that
00216  * may cross the application/DLL boundary
00217  *
00218  * Although WIN16 is not a supported platform there is code that used to
00219  * support WIN16 in use and these macros let it continue to operate
00220  * unchanged
00221  */
00222 #if !defined(MS_CALLBACK) || !defined(MS_FAR)
00223 #ifdef WIN16
00224 #define MS_CALLBACK   _far _loadds
00225 #define MS_FAR        _far
00226 #else /* !WIN16 */
00227 #define MS_CALLBACK
00228 #define MS_FAR
00229 #endif /* WIN16 */
00230 #endif /* !MS_CALLBACK || MS_FAR */
00231 
00232 /*
00233  * MS_STATIC is used for items that are placed on the stack normally but
00234  * are safe to make static (i.e. global) in environments with small runtime
00235  * stacks
00236  */
00237 #ifndef MS_STATIC
00238 #if defined(WIN16) || defined(MSDOS) || defined(UNDER_PALMOS)
00239 #define MS_STATIC   static
00240 #else
00241 #define MS_STATIC
00242 #endif /* !WIN16 !MSDOS !UNDER_PALMOS */
00243 #endif /* !MS_STATIC */
00244 
00245 #if !defined(RCOM_LEAN)
00246 
00247 /* include basic platform IO definitions
00248  *
00249  *  This file should be included prior to r_mem.h when building
00250  *  for vxWorks with the Tornado 2 environment. There is a define
00251  *  for Free in vxWorks that is also used in r_mem.h
00252  */
00253 
00254 /* r_vxworks.h should be included before r_sock.h to prevent an
00255  * out-of order definition in Tornado 1 (netdb.h is not supplied).
00256  * r_mem.h has to be defined after r_sock.h for VxWorks.
00257  */
00258 
00259 #ifdef VXWORKS
00260 #include "r_vxworks.h"
00261 #endif
00262 
00263 #if (R_OS == R_OS_NUCLEUS)
00264 #include "r_nucleus.h"
00265 #endif /* R_OS == R_OS_NUCLEUS */
00266 
00267 
00268 #if !defined(NO_SOCK)
00269 #include "r_sock.h"
00270 #endif
00271 
00272 #include "r_mem.h"
00273 
00274 #if defined(PLATFORM_IMODE)
00275 #include "r_imode.h"
00276 #endif /* !PLATFORM_IMODE */
00277 
00278 /* include support for asserts */
00279 #include "r_assert.h"
00280 
00281 /* include the endian macros */
00282 #include "r_endian.h"
00283 
00284 /* include the locking routines and CRYPTO definitions */
00285 #include "r_lock.h"
00286 
00287 /* include the surrender functions */
00288 #include "r_surr.h"
00289 
00290 /* include any custom string fucntions */
00291 #include "r_str.h"
00292 
00293 #endif /* !defined(RCOM_LEAN) */
00294 
00295 #ifndef Memcpy
00296 
00300 #define Memcpy memcpy
00301 #endif
00302 
00303 #ifndef Memmove
00304 
00308 #define Memmove memmove
00309 #endif
00310 
00311 #ifndef Memset
00312 
00316 #define Memset memset
00317 #endif
00318 
00319 #ifndef Memcmp
00320 
00324 #define Memcmp memcmp
00325 #endif
00326 
00327 #ifndef Strcmp
00328 
00332 #define Strcmp strcmp
00333 #endif
00334 
00335 #ifndef Strncmp
00336 
00340 #define Strncmp strncmp
00341 #endif
00342 
00343 #ifndef Strlen
00344 
00348 #define Strlen strlen
00349 #endif
00350 
00351 #ifndef Strcpy
00352 
00356 #define Strcpy strcpy
00357 #endif
00358 
00359 #ifndef Strncpy
00360 
00364 #define Strncpy strncpy
00365 #endif
00366 
00367 #ifndef Strcat
00368 
00372 #define Strcat strcat
00373 #endif
00374 
00375 #ifndef Strtok
00376 
00380 #define Strtok strtok
00381 #endif
00382 
00383 #ifndef Qsort
00384 
00388 #define Qsort(a,b,c,d)  \
00389                 qsort((void *)(a),(size_t)(b),(size_t)(c),(d))
00390 #endif
00391 
00392 #ifndef Strtol
00393 
00397 #define Strtol strtol
00398 #endif
00399 
00400 #ifndef Strchr
00401 
00405 #define Strchr strchr
00406 #endif
00407 
00408 #ifndef Strstr
00409 
00413 #define Strstr strstr
00414 #endif
00415 
00416 #ifndef Strtoul
00417 
00421 #define Strtoul strtoul
00422 #endif
00423 
00424 #ifndef Bsearch
00425 
00429 #define Bsearch(a,b,c,d,e) \
00430         bsearch((void *)(a),(void *)(b),(size_t)(c),(size_t)(d),(e))
00431 #endif
00432 
00433 #ifndef Remove
00434 
00438 #define Remove remove
00439 #endif
00440 
00441 #ifndef Getenv
00442 
00446 #define Getenv getenv
00447 #endif
00448 
00449 #ifndef Putenv
00450 
00454 #define Putenv putenv
00455 #endif
00456 
00457 
00458 
00459 #ifndef Isdigit
00460 #ifndef NO_ISDIGIT
00461 
00462 #ifndef NO_CTYPE_H
00463 #include <ctype.h>
00464 #endif
00465 
00470 #define Isdigit isdigit
00471 #else
00472 #define Isdigit(a) (a >= '0' && a <= '9')
00473 #endif
00474 #endif
00475 
00476 /* Functions for handling hex strings. */
00477 #include "r_hexstr.h"
00478 
00479 #ifndef CCONV
00480 #define CCONV
00481 #endif
00482 
00483 #ifndef PRE_CCONV
00484 #define PRE_CCONV
00485 #endif
00486 
00487 
00488 /* Common/shared structure definitions */
00492 typedef struct r_item_st
00493 {
00497     unsigned int len;
00498 
00502     unsigned char *data;
00503 } R_ITEM;
00504 
00508 typedef struct r_titem_st
00509 {
00513     unsigned int type;
00514 
00518     unsigned int len;
00519 
00523     unsigned char *data;
00524 } R_TITEM;
00525 
00526 /* Common/shared string types */
00527 
00534 #define R_UTF8 char *
00535 
00536 #if defined(PLATFORM_LINUX_KERNEL)
00537 #include <linux/limits.h>
00538 #define LONG_BIT 32
00539 #undef  LONG_MAX
00540 #define LONG_MAX 2147483647
00541 #else
00542 #include <limits.h>
00543 #endif
00544 
00545 #if (defined(LONG_BIT) && (LONG_BIT == 32))         || \
00546     (defined(LONG_MAX) && (LONG_MAX == 2147483647))
00547 
00551 #define R_INT32         long
00552 
00555 #define R_UINT32        unsigned long
00556 
00557 #ifdef WIN32
00558 #define R_INT64         __int64
00559 #define R_UINT64        unsigned __int64
00560 #else
00561 #define R_INT64         long long
00562 #define R_UINT64        unsigned long long
00563 #endif
00564 #elif (defined(LONG_BIT) && (LONG_BIT == 64))         || \
00565       (defined(LONG_MAX) && (LONG_MAX == 9223372036854775807L))
00566 #define R_INT64         long
00567 #define R_UINT64        unsigned long
00568 #endif
00569 #if  (!defined(R_UINT32)) && \
00570      ((defined(INT_BIT) && (INT_BIT == 32))        || \
00571       (defined(INT_MAX) && (INT_MAX == 2147483647)))
00572 #define R_INT32         int
00573 #define R_UINT32        unsigned int
00574 #endif
00575 
00579 #define R_INT16         short
00580 
00583 #define R_UINT16        unsigned short
00584 
00585 #ifndef R_INT32
00586 COMPILE ERROR = Cannot find a 32 bit data type for this platform;
00587 #endif
00588 
00589 /* When using the Test Framework the <i>main</i> must be replaced with the
00590  * Test Framework <i>main</i> which sets up the Test Framework. As r_com.h
00591  * should be included in all unit tests, system tests, and samples, add
00592  * platform specific definitions of <i>main</i> here.
00593  *
00594  * @note To override TEST_FRAMEWORK use OVERRIDE_TEST_FRAMEWORK. This currently
00595  * only available on a per file basis as the build system does not support
00596  * #defines on a per directory basis. The use of this negate all #defines
00597  * triggered by TEST_FRAMEWORK.
00598  *
00599  */
00600 
00601 #ifdef TEST_FRAMEWORK
00602 #ifndef OVERRIDE_TEST_FRAMEWORK
00603 #if defined(PLATFORM_SOLARIS) || defined(PLATFORM_LINUX) || \
00604  (defined(PLATFORM_WINDOWS) && !defined(UNDER_CE)) || defined(PLATFORM_EPOC)
00605 #include "teremote_comms.h"
00606 #include "te_override.h"
00607 #endif /* platform ids */
00608 #endif /* OVERRIDE_TEST_FRAMEWORK */
00609 #endif /* TEST_FRAMEWORK */
00610 
00611 #ifdef  __cplusplus
00612 }
00613 #endif
00614 
00615 #ifndef EVAL_CHECK_DATE
00616 #define EVAL_CHECK_DATE()
00617 #endif
00618 
00619 #endif /* HEADER_COMMON_R_COM_H */
00620 

Copyright (c) 1999-2005 RSA Security Inc. All rights reserved. 072-001001-2100-001-000 - 2.1