mbed TLS v1.3.17
platform.h
Go to the documentation of this file.
1 
24 #ifndef POLARSSL_PLATFORM_H
25 #define POLARSSL_PLATFORM_H
26 
27 #if !defined(POLARSSL_CONFIG_FILE)
28 #include "config.h"
29 #else
30 #include POLARSSL_CONFIG_FILE
31 #endif
32 
33 /* Temporary compatibility hack for to keep MEMORY_C working */
34 #if defined(POLARSSL_MEMORY_C) && !defined(POLARSSL_PLATFORM_MEMORY)
35 #define POLARSSL_PLATFORM_MEMORY
36 #endif
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
50 #if !defined(POLARSSL_PLATFORM_NO_STD_FUNCTIONS)
51 #include <stdio.h>
52 #include <stdlib.h>
53 #if !defined(POLARSSL_PLATFORM_STD_SNPRINTF)
54 #define POLARSSL_PLATFORM_STD_SNPRINTF snprintf
55 #endif
56 #if !defined(POLARSSL_PLATFORM_STD_PRINTF)
57 #define POLARSSL_PLATFORM_STD_PRINTF printf
58 #endif
59 #if !defined(POLARSSL_PLATFORM_STD_FPRINTF)
60 #define POLARSSL_PLATFORM_STD_FPRINTF fprintf
61 #endif
62 #if !defined(POLARSSL_PLATFORM_STD_MALLOC)
63 #define POLARSSL_PLATFORM_STD_MALLOC malloc
64 #endif
65 #if !defined(POLARSSL_PLATFORM_STD_FREE)
66 #define POLARSSL_PLATFORM_STD_FREE free
67 #endif
68 #if !defined(POLARSSL_PLATFORM_STD_EXIT)
69 #define POLARSSL_PLATFORM_STD_EXIT exit
70 #endif
71 #else /* POLARSSL_PLATFORM_NO_STD_FUNCTIONS */
72 #if defined(POLARSSL_PLATFORM_STD_MEM_HDR)
73 #include POLARSSL_PLATFORM_STD_MEM_HDR
74 #endif
75 #endif /* POLARSSL_PLATFORM_NO_STD_FUNCTIONS */
76 
77 /* \} name SECTION: Module settings */
78 
79 /*
80  * The function pointers for malloc and free
81  */
82 #if defined(POLARSSL_PLATFORM_MEMORY)
83 #if defined(POLARSSL_PLATFORM_FREE_MACRO) && \
84  defined(POLARSSL_PLATFORM_MALLOC_MACRO)
85 #define polarssl_free POLARSSL_PLATFORM_FREE_MACRO
86 #define polarssl_malloc POLARSSL_PLATFORM_MALLOC_MACRO
87 #else
88 /* For size_t */
89 #include <stddef.h>
90 extern void * (*polarssl_malloc)( size_t len );
91 extern void (*polarssl_free)( void *ptr );
92 
101 int platform_set_malloc_free( void * (*malloc_func)( size_t ),
102  void (*free_func)( void * ) );
103 #endif /* POLARSSL_PLATFORM_FREE_MACRO && POLARSSL_PLATFORM_MALLOC_MACRO */
104 #else /* !POLARSSL_PLATFORM_MEMORY */
105 #define polarssl_free free
106 #define polarssl_malloc malloc
107 #endif /* POLARSSL_PLATFORM_MEMORY && !POLARSSL_PLATFORM_{FREE,MALLOC}_MACRO */
108 
109 /*
110  * The function pointers for fprintf
111  */
112 #if defined(POLARSSL_PLATFORM_FPRINTF_ALT)
113 /* We need FILE * */
114 #include <stdio.h>
115 extern int (*polarssl_fprintf)( FILE *stream, const char *format, ... );
116 
124 int platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
125  ... ) );
126 #else
127 #if defined(POLARSSL_PLATFORM_FPRINTF_MACRO)
128 #define polarssl_fprintf POLARSSL_PLATFORM_FPRINTF_MACRO
129 #else
130 #define polarssl_fprintf fprintf
131 #endif /* POLARSSL_PLATFORM_FPRINTF_MACRO */
132 #endif /* POLARSSL_PLATFORM_FPRINTF_ALT */
133 
134 /*
135  * The function pointers for printf
136  */
137 #if defined(POLARSSL_PLATFORM_PRINTF_ALT)
138 extern int (*polarssl_printf)( const char *format, ... );
139 
147 int platform_set_printf( int (*printf_func)( const char *, ... ) );
148 #else /* !POLARSSL_PLATFORM_PRINTF_ALT */
149 #if defined(POLARSSL_PLATFORM_PRINTF_MACRO)
150 #define polarssl_printf POLARSSL_PLATFORM_PRINTF_MACRO
151 #else
152 #define polarssl_printf printf
153 #endif /* POLARSSL_PLATFORM_PRINTF_MACRO */
154 #endif /* POLARSSL_PLATFORM_PRINTF_ALT */
155 
156 /*
157  * The function pointers for snprintf
158  */
159 #if defined(POLARSSL_PLATFORM_SNPRINTF_ALT)
160 extern int (*polarssl_snprintf)( char * s, size_t n, const char * format, ... );
161 
169 int platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
170  const char * format, ... ) );
171 #else /* POLARSSL_PLATFORM_SNPRINTF_ALT */
172 #if defined(POLARSSL_PLATFORM_SNPRINTF_MACRO)
173 #define polarssl_snprintf POLARSSL_PLATFORM_SNPRINTF_MACRO
174 #else
175 #define polarssl_snprintf snprintf
176 #endif /* POLARSSL_PLATFORM_SNPRINTF_MACRO */
177 #endif /* POLARSSL_PLATFORM_SNPRINTF_ALT */
178 
179 /*
180  * The function pointers for exit
181  */
182 #if defined(POLARSSL_PLATFORM_EXIT_ALT)
183 extern void (*polarssl_exit)( int status );
184 
192 int platform_set_exit( void (*exit_func)( int status ) );
193 #else
194 #if defined(POLARSSL_PLATFORM_EXIT_MACRO)
195 #define polarssl_exit POLARSSL_PLATFORM_EXIT_MACRO
196 #else
197 #define polarssl_exit exit
198 #endif /* POLARSSL_PLATFORM_EXIT_MACRO */
199 #endif /* POLARSSL_PLATFORM_EXIT_ALT */
200 
201 #ifdef __cplusplus
202 }
203 #endif
204 
205 #endif /* platform.h */
#define polarssl_free
Definition: platform.h:105
Configuration options (set of defines)
#define polarssl_exit
Definition: platform.h:197
#define polarssl_snprintf
Definition: platform.h:175
#define polarssl_printf
Definition: platform.h:152
#define polarssl_fprintf
Definition: platform.h:130