blob: d57cbc8286acc077b04f1634e5b89ee31aaf5a9f [file] [log] [blame]
Paul Bakker747a83a2014-02-01 22:50:07 +01001/*
2 * Platform abstraction layer
3 *
4 * Copyright (C) 2006-2014, Brainspark B.V.
5 *
6 * This file is part of PolarSSL (http://www.polarssl.org)
7 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
8 *
9 * All rights reserved.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 */
25
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020026#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakker747a83a2014-02-01 22:50:07 +010027#include "polarssl/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020028#else
29#include POLARSSL_CONFIG_FILE
30#endif
Paul Bakker747a83a2014-02-01 22:50:07 +010031
32#if defined(POLARSSL_PLATFORM_C)
33
34#include "polarssl/platform.h"
35
Paul Bakkerdefc0ca2014-02-04 17:30:24 +010036#if defined(POLARSSL_PLATFORM_MEMORY)
37#if !defined(POLARSSL_PLATFORM_STD_MALLOC)
38static void *platform_malloc_uninit( size_t len )
39{
40 ((void) len);
41 return( NULL );
42}
43
Manuel Pégourié-Gonnard74bc68a2014-04-02 13:20:00 +020044#define POLARSSL_PLATFORM_STD_MALLOC platform_malloc_uninit
Paul Bakkerdefc0ca2014-02-04 17:30:24 +010045#endif /* !POLARSSL_PLATFORM_STD_MALLOC */
46
47#if !defined(POLARSSL_PLATFORM_STD_FREE)
48static void platform_free_uninit( void *ptr )
49{
50 ((void) ptr);
51}
52
Manuel Pégourié-Gonnard74bc68a2014-04-02 13:20:00 +020053#define POLARSSL_PLATFORM_STD_FREE platform_free_uninit
Paul Bakkerdefc0ca2014-02-04 17:30:24 +010054#endif /* !POLARSSL_PLATFORM_STD_FREE */
55
56void * (*polarssl_malloc)( size_t ) = POLARSSL_PLATFORM_STD_MALLOC;
57void (*polarssl_free)( void * ) = POLARSSL_PLATFORM_STD_FREE;
58
59int platform_set_malloc_free( void * (*malloc_func)( size_t ),
60 void (*free_func)( void * ) )
61{
62 polarssl_malloc = malloc_func;
63 polarssl_free = free_func;
64 return( 0 );
65}
66#endif /* POLARSSL_PLATFORM_MEMORY */
67
Paul Bakker747a83a2014-02-01 22:50:07 +010068#if defined(POLARSSL_PLATFORM_PRINTF_ALT)
69#if !defined(POLARSSL_PLATFORM_STD_PRINTF)
70/*
71 * Make dummy function to prevent NULL pointer dereferences
72 */
73static int platform_printf_uninit( const char *format, ... )
74{
75 ((void) format);
76 return( 0 );
77}
78
79#define POLARSSL_PLATFORM_STD_PRINTF platform_printf_uninit
80#endif /* !POLARSSL_PLATFORM_STD_PRINTF */
81
82int (*polarssl_printf)( const char *, ... ) = POLARSSL_PLATFORM_STD_PRINTF;
83
84int platform_set_printf( int (*printf_func)( const char *, ... ) )
85{
86 polarssl_printf = printf_func;
87 return( 0 );
88}
89#endif /* POLARSSL_PLATFORM_PRINTF_ALT */
90
91#if defined(POLARSSL_PLATFORM_FPRINTF_ALT)
92#if !defined(POLARSSL_PLATFORM_STD_FPRINTF)
93/*
94 * Make dummy function to prevent NULL pointer dereferences
95 */
96static int platform_fprintf_uninit( FILE *stream, const char *format, ... )
97{
98 ((void) stream);
99 ((void) format);
100 return( 0 );
101}
102
Paul Bakker10a9dd32014-04-25 11:18:34 +0200103#define POLARSSL_PLATFORM_STD_FPRINTF platform_fprintf_uninit
Paul Bakker747a83a2014-02-01 22:50:07 +0100104#endif /* !POLARSSL_PLATFORM_STD_FPRINTF */
105
106int (*polarssl_fprintf)( FILE *, const char *, ... ) =
107 POLARSSL_PLATFORM_STD_FPRINTF;
108
109int platform_set_fprintf( int (*fprintf_func)( FILE *, const char *, ... ) )
110{
111 polarssl_fprintf = fprintf_func;
112 return( 0 );
113}
114#endif /* POLARSSL_PLATFORM_FPRINTF_ALT */
115
116#endif /* POLARSSL_PLATFORM_C */