blob: 823b17d13c834a34a1b78a1f150f337abaa3ea40 [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
26#include "polarssl/config.h"
27
28#if defined(POLARSSL_PLATFORM_C)
29
30#include "polarssl/platform.h"
31
Paul Bakkerdefc0ca2014-02-04 17:30:24 +010032#if defined(POLARSSL_PLATFORM_MEMORY)
33#if !defined(POLARSSL_PLATFORM_STD_MALLOC)
34static void *platform_malloc_uninit( size_t len )
35{
36 ((void) len);
37 return( NULL );
38}
39
40#define POLARSSL_PLATFORM_STD_MALLOC memory_malloc_uninit
41#endif /* !POLARSSL_PLATFORM_STD_MALLOC */
42
43#if !defined(POLARSSL_PLATFORM_STD_FREE)
44static void platform_free_uninit( void *ptr )
45{
46 ((void) ptr);
47}
48
49#define POLARSSL_PLATFORM_STD_FREE memory_free_uninit
50#endif /* !POLARSSL_PLATFORM_STD_FREE */
51
52void * (*polarssl_malloc)( size_t ) = POLARSSL_PLATFORM_STD_MALLOC;
53void (*polarssl_free)( void * ) = POLARSSL_PLATFORM_STD_FREE;
54
55int platform_set_malloc_free( void * (*malloc_func)( size_t ),
56 void (*free_func)( void * ) )
57{
58 polarssl_malloc = malloc_func;
59 polarssl_free = free_func;
60 return( 0 );
61}
62#endif /* POLARSSL_PLATFORM_MEMORY */
63
Paul Bakker747a83a2014-02-01 22:50:07 +010064#if defined(POLARSSL_PLATFORM_PRINTF_ALT)
65#if !defined(POLARSSL_PLATFORM_STD_PRINTF)
66/*
67 * Make dummy function to prevent NULL pointer dereferences
68 */
69static int platform_printf_uninit( const char *format, ... )
70{
71 ((void) format);
72 return( 0 );
73}
74
75#define POLARSSL_PLATFORM_STD_PRINTF platform_printf_uninit
76#endif /* !POLARSSL_PLATFORM_STD_PRINTF */
77
78int (*polarssl_printf)( const char *, ... ) = POLARSSL_PLATFORM_STD_PRINTF;
79
80int platform_set_printf( int (*printf_func)( const char *, ... ) )
81{
82 polarssl_printf = printf_func;
83 return( 0 );
84}
85#endif /* POLARSSL_PLATFORM_PRINTF_ALT */
86
87#if defined(POLARSSL_PLATFORM_FPRINTF_ALT)
88#if !defined(POLARSSL_PLATFORM_STD_FPRINTF)
89/*
90 * Make dummy function to prevent NULL pointer dereferences
91 */
92static int platform_fprintf_uninit( FILE *stream, const char *format, ... )
93{
94 ((void) stream);
95 ((void) format);
96 return( 0 );
97}
98
99#define POLARSSL_PLATFORM_STD_fPRINTF platform_fprintf_uninit
100#endif /* !POLARSSL_PLATFORM_STD_FPRINTF */
101
102int (*polarssl_fprintf)( FILE *, const char *, ... ) =
103 POLARSSL_PLATFORM_STD_FPRINTF;
104
105int platform_set_fprintf( int (*fprintf_func)( FILE *, const char *, ... ) )
106{
107 polarssl_fprintf = fprintf_func;
108 return( 0 );
109}
110#endif /* POLARSSL_PLATFORM_FPRINTF_ALT */
111
112#endif /* POLARSSL_PLATFORM_C */