/ext/polarssl-1.3/include/polarssl/platform.h

https://github.com/CrashSerious/showtime · C Header · 205 lines · 102 code · 18 blank · 85 comment · 2 complexity · febd457adc6eee3a1ffe6a23e9344e93 MD5 · raw file

  1. /**
  2. * \file platform.h
  3. *
  4. * \brief mbed TLS Platform abstraction layer
  5. *
  6. * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
  7. *
  8. * This file is part of mbed TLS (https://tls.mbed.org)
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License along
  21. * with this program; if not, write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  23. */
  24. #ifndef POLARSSL_PLATFORM_H
  25. #define POLARSSL_PLATFORM_H
  26. #if !defined(POLARSSL_CONFIG_FILE)
  27. #include "config.h"
  28. #else
  29. #include POLARSSL_CONFIG_FILE
  30. #endif
  31. /* Temporary compatibility hack for to keep MEMORY_C working */
  32. #if defined(POLARSSL_MEMORY_C) && !defined(POLARSSL_PLATFORM_MEMORY)
  33. #define POLARSSL_PLATFORM_MEMORY
  34. #endif
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /**
  39. * \name SECTION: Module settings
  40. *
  41. * The configuration options you can set for this module are in this section.
  42. * Either change them in config.h or define them on the compiler command line.
  43. * \{
  44. */
  45. #if !defined(POLARSSL_PLATFORM_NO_STD_FUNCTIONS)
  46. #include <stdio.h>
  47. #include <stdlib.h>
  48. #if !defined(POLARSSL_PLATFORM_STD_SNPRINTF)
  49. #define POLARSSL_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use */
  50. #endif
  51. #if !defined(POLARSSL_PLATFORM_STD_PRINTF)
  52. #define POLARSSL_PLATFORM_STD_PRINTF printf /**< Default printf to use */
  53. #endif
  54. #if !defined(POLARSSL_PLATFORM_STD_FPRINTF)
  55. #define POLARSSL_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use */
  56. #endif
  57. #if !defined(POLARSSL_PLATFORM_STD_MALLOC)
  58. #define POLARSSL_PLATFORM_STD_MALLOC malloc /**< Default allocator to use */
  59. #endif
  60. #if !defined(POLARSSL_PLATFORM_STD_FREE)
  61. #define POLARSSL_PLATFORM_STD_FREE free /**< Default free to use */
  62. #endif
  63. #if !defined(POLARSSL_PLATFORM_STD_EXIT)
  64. #define POLARSSL_PLATFORM_STD_EXIT exit /**< Default free to use */
  65. #endif
  66. #else /* POLARSSL_PLATFORM_NO_STD_FUNCTIONS */
  67. #if defined(POLARSSL_PLATFORM_STD_MEM_HDR)
  68. #include POLARSSL_PLATFORM_STD_MEM_HDR
  69. #endif
  70. #endif /* POLARSSL_PLATFORM_NO_STD_FUNCTIONS */
  71. /* \} name SECTION: Module settings */
  72. /*
  73. * The function pointers for malloc and free
  74. */
  75. #if defined(POLARSSL_PLATFORM_MEMORY)
  76. #if defined(POLARSSL_PLATFORM_FREE_MACRO) && \
  77. defined(POLARSSL_PLATFORM_MALLOC_MACRO)
  78. #define polarssl_free POLARSSL_PLATFORM_FREE_MACRO
  79. #define polarssl_malloc POLARSSL_PLATFORM_MALLOC_MACRO
  80. #else
  81. /* For size_t */
  82. #include <stddef.h>
  83. extern void * (*polarssl_malloc)( size_t len );
  84. extern void (*polarssl_free)( void *ptr );
  85. /**
  86. * \brief Set your own memory implementation function pointers
  87. *
  88. * \param malloc_func the malloc function implementation
  89. * \param free_func the free function implementation
  90. *
  91. * \return 0 if successful
  92. */
  93. int platform_set_malloc_free( void * (*malloc_func)( size_t ),
  94. void (*free_func)( void * ) );
  95. #endif /* POLARSSL_PLATFORM_FREE_MACRO && POLARSSL_PLATFORM_MALLOC_MACRO */
  96. #else /* !POLARSSL_PLATFORM_MEMORY */
  97. #define polarssl_free free
  98. #define polarssl_malloc malloc
  99. #endif /* POLARSSL_PLATFORM_MEMORY && !POLARSSL_PLATFORM_{FREE,MALLOC}_MACRO */
  100. /*
  101. * The function pointers for fprintf
  102. */
  103. #if defined(POLARSSL_PLATFORM_FPRINTF_ALT)
  104. /* We need FILE * */
  105. #include <stdio.h>
  106. extern int (*polarssl_fprintf)( FILE *stream, const char *format, ... );
  107. /**
  108. * \brief Set your own fprintf function pointer
  109. *
  110. * \param fprintf_func the fprintf function implementation
  111. *
  112. * \return 0
  113. */
  114. int platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
  115. ... ) );
  116. #else
  117. #if defined(POLARSSL_PLATFORM_FPRINTF_MACRO)
  118. #define polarssl_fprintf POLARSSL_PLATFORM_FPRINTF_MACRO
  119. #else
  120. #define polarssl_fprintf fprintf
  121. #endif /* POLARSSL_PLATFORM_FPRINTF_MACRO */
  122. #endif /* POLARSSL_PLATFORM_FPRINTF_ALT */
  123. /*
  124. * The function pointers for printf
  125. */
  126. #if defined(POLARSSL_PLATFORM_PRINTF_ALT)
  127. extern int (*polarssl_printf)( const char *format, ... );
  128. /**
  129. * \brief Set your own printf function pointer
  130. *
  131. * \param printf_func the printf function implementation
  132. *
  133. * \return 0
  134. */
  135. int platform_set_printf( int (*printf_func)( const char *, ... ) );
  136. #else /* !POLARSSL_PLATFORM_PRINTF_ALT */
  137. #if defined(POLARSSL_PLATFORM_PRINTF_MACRO)
  138. #define polarssl_printf POLARSSL_PLATFORM_PRINTF_MACRO
  139. #else
  140. #define polarssl_printf printf
  141. #endif /* POLARSSL_PLATFORM_PRINTF_MACRO */
  142. #endif /* POLARSSL_PLATFORM_PRINTF_ALT */
  143. /*
  144. * The function pointers for snprintf
  145. */
  146. #if defined(POLARSSL_PLATFORM_SNPRINTF_ALT)
  147. extern int (*polarssl_snprintf)( char * s, size_t n, const char * format, ... );
  148. /**
  149. * \brief Set your own snprintf function pointer
  150. *
  151. * \param snprintf_func the snprintf function implementation
  152. *
  153. * \return 0
  154. */
  155. int platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
  156. const char * format, ... ) );
  157. #else /* POLARSSL_PLATFORM_SNPRINTF_ALT */
  158. #if defined(POLARSSL_PLATFORM_SNPRINTF_MACRO)
  159. #define polarssl_snprintf POLARSSL_PLATFORM_SNPRINTF_MACRO
  160. #else
  161. #define polarssl_snprintf snprintf
  162. #endif /* POLARSSL_PLATFORM_SNPRINTF_MACRO */
  163. #endif /* POLARSSL_PLATFORM_SNPRINTF_ALT */
  164. /*
  165. * The function pointers for exit
  166. */
  167. #if defined(POLARSSL_PLATFORM_EXIT_ALT)
  168. extern void (*polarssl_exit)( int status );
  169. /**
  170. * \brief Set your own exit function pointer
  171. *
  172. * \param exit_func the exit function implementation
  173. *
  174. * \return 0
  175. */
  176. int platform_set_exit( void (*exit_func)( int status ) );
  177. #else
  178. #if defined(POLARSSL_PLATFORM_EXIT_MACRO)
  179. #define polarssl_exit POLARSSL_PLATFORM_EXIT_MACRO
  180. #else
  181. #define polarssl_exit exit
  182. #endif /* POLARSSL_PLATFORM_EXIT_MACRO */
  183. #endif /* POLARSSL_PLATFORM_EXIT_ALT */
  184. #ifdef __cplusplus
  185. }
  186. #endif
  187. #endif /* platform.h */