2 * Platform abstraction layer
4 * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
6 * This file is part of mbed TLS (https://tls.mbed.org)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #if !defined(POLARSSL_CONFIG_FILE)
24 #include "polarssl/config.h"
26 #include POLARSSL_CONFIG_FILE
29 #if defined(POLARSSL_PLATFORM_C)
31 #include "polarssl/platform.h"
33 #if defined(POLARSSL_PLATFORM_MEMORY)
34 #if !defined(POLARSSL_PLATFORM_STD_MALLOC)
35 static void *platform_malloc_uninit( size_t len
)
41 #define POLARSSL_PLATFORM_STD_MALLOC platform_malloc_uninit
42 #endif /* !POLARSSL_PLATFORM_STD_MALLOC */
44 #if !defined(POLARSSL_PLATFORM_STD_FREE)
45 static void platform_free_uninit( void *ptr
)
50 #define POLARSSL_PLATFORM_STD_FREE platform_free_uninit
51 #endif /* !POLARSSL_PLATFORM_STD_FREE */
53 void * (*polarssl_malloc
)( size_t ) = POLARSSL_PLATFORM_STD_MALLOC
;
54 void (*polarssl_free
)( void * ) = POLARSSL_PLATFORM_STD_FREE
;
56 int platform_set_malloc_free( void * (*malloc_func
)( size_t ),
57 void (*free_func
)( void * ) )
59 polarssl_malloc
= malloc_func
;
60 polarssl_free
= free_func
;
63 #endif /* POLARSSL_PLATFORM_MEMORY */
65 #if defined(POLARSSL_PLATFORM_SNPRINTF_ALT)
66 #if !defined(POLARSSL_PLATFORM_STD_SNPRINTF)
68 * Make dummy function to prevent NULL pointer dereferences
70 static int platform_snprintf_uninit( char * s
, size_t n
,
71 const char * format
, ... )
79 #define POLARSSL_PLATFORM_STD_SNPRINTF platform_snprintf_uninit
80 #endif /* !POLARSSL_PLATFORM_STD_SNPRINTF */
82 int (*polarssl_snprintf
)( char * s
, size_t n
,
84 ... ) = POLARSSL_PLATFORM_STD_SNPRINTF
;
86 int platform_set_snprintf( int (*snprintf_func
)( char * s
, size_t n
,
90 polarssl_snprintf
= snprintf_func
;
93 #endif /* POLARSSL_PLATFORM_SNPRINTF_ALT */
95 #if defined(POLARSSL_PLATFORM_PRINTF_ALT)
96 #if !defined(POLARSSL_PLATFORM_STD_PRINTF)
98 * Make dummy function to prevent NULL pointer dereferences
100 static int platform_printf_uninit( const char *format
, ... )
106 #define POLARSSL_PLATFORM_STD_PRINTF platform_printf_uninit
107 #endif /* !POLARSSL_PLATFORM_STD_PRINTF */
109 int (*polarssl_printf
)( const char *, ... ) = POLARSSL_PLATFORM_STD_PRINTF
;
111 int platform_set_printf( int (*printf_func
)( const char *, ... ) )
113 polarssl_printf
= printf_func
;
116 #endif /* POLARSSL_PLATFORM_PRINTF_ALT */
118 #if defined(POLARSSL_PLATFORM_FPRINTF_ALT)
119 #if !defined(POLARSSL_PLATFORM_STD_FPRINTF)
121 * Make dummy function to prevent NULL pointer dereferences
123 static int platform_fprintf_uninit( FILE *stream
, const char *format
, ... )
130 #define POLARSSL_PLATFORM_STD_FPRINTF platform_fprintf_uninit
131 #endif /* !POLARSSL_PLATFORM_STD_FPRINTF */
133 int (*polarssl_fprintf
)( FILE *, const char *, ... ) =
134 POLARSSL_PLATFORM_STD_FPRINTF
;
136 int platform_set_fprintf( int (*fprintf_func
)( FILE *, const char *, ... ) )
138 polarssl_fprintf
= fprintf_func
;
141 #endif /* POLARSSL_PLATFORM_FPRINTF_ALT */
143 #if defined(POLARSSL_PLATFORM_EXIT_ALT)
144 #if !defined(POLARSSL_PLATFORM_STD_EXIT)
146 * Make dummy function to prevent NULL pointer dereferences
148 static void platform_exit_uninit( int status
)
153 #define POLARSSL_PLATFORM_STD_EXIT platform_exit_uninit
154 #endif /* !POLARSSL_PLATFORM_STD_EXIT */
156 void (*polarssl_exit
)( int status
) = POLARSSL_PLATFORM_STD_EXIT
;
158 int platform_set_exit( void (*exit_func
)( int status
) )
160 polarssl_exit
= exit_func
;
163 #endif /* POLARSSL_PLATFORM_EXIT_ALT */
165 #endif /* POLARSSL_PLATFORM_C */