Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 1 | /* |
| 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é-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 26 | #if !defined(POLARSSL_CONFIG_FILE) |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 27 | #include "polarssl/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 28 | #else |
| 29 | #include POLARSSL_CONFIG_FILE |
| 30 | #endif |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 31 | |
| 32 | #if defined(POLARSSL_PLATFORM_C) |
| 33 | |
| 34 | #include "polarssl/platform.h" |
| 35 | |
Paul Bakker | defc0ca | 2014-02-04 17:30:24 +0100 | [diff] [blame] | 36 | #if defined(POLARSSL_PLATFORM_MEMORY) |
| 37 | #if !defined(POLARSSL_PLATFORM_STD_MALLOC) |
| 38 | static void *platform_malloc_uninit( size_t len ) |
| 39 | { |
| 40 | ((void) len); |
| 41 | return( NULL ); |
| 42 | } |
| 43 | |
Manuel Pégourié-Gonnard | 74bc68a | 2014-04-02 13:20:00 +0200 | [diff] [blame] | 44 | #define POLARSSL_PLATFORM_STD_MALLOC platform_malloc_uninit |
Paul Bakker | defc0ca | 2014-02-04 17:30:24 +0100 | [diff] [blame] | 45 | #endif /* !POLARSSL_PLATFORM_STD_MALLOC */ |
| 46 | |
| 47 | #if !defined(POLARSSL_PLATFORM_STD_FREE) |
| 48 | static void platform_free_uninit( void *ptr ) |
| 49 | { |
| 50 | ((void) ptr); |
| 51 | } |
| 52 | |
Manuel Pégourié-Gonnard | 74bc68a | 2014-04-02 13:20:00 +0200 | [diff] [blame] | 53 | #define POLARSSL_PLATFORM_STD_FREE platform_free_uninit |
Paul Bakker | defc0ca | 2014-02-04 17:30:24 +0100 | [diff] [blame] | 54 | #endif /* !POLARSSL_PLATFORM_STD_FREE */ |
| 55 | |
| 56 | void * (*polarssl_malloc)( size_t ) = POLARSSL_PLATFORM_STD_MALLOC; |
| 57 | void (*polarssl_free)( void * ) = POLARSSL_PLATFORM_STD_FREE; |
| 58 | |
| 59 | int 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 Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 68 | #if defined(POLARSSL_PLATFORM_PRINTF_ALT) |
| 69 | #if !defined(POLARSSL_PLATFORM_STD_PRINTF) |
| 70 | /* |
| 71 | * Make dummy function to prevent NULL pointer dereferences |
| 72 | */ |
| 73 | static 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 | |
| 82 | int (*polarssl_printf)( const char *, ... ) = POLARSSL_PLATFORM_STD_PRINTF; |
| 83 | |
| 84 | int 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 | */ |
| 96 | static int platform_fprintf_uninit( FILE *stream, const char *format, ... ) |
| 97 | { |
| 98 | ((void) stream); |
| 99 | ((void) format); |
| 100 | return( 0 ); |
| 101 | } |
| 102 | |
Paul Bakker | 10a9dd3 | 2014-04-25 11:18:34 +0200 | [diff] [blame] | 103 | #define POLARSSL_PLATFORM_STD_FPRINTF platform_fprintf_uninit |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 104 | #endif /* !POLARSSL_PLATFORM_STD_FPRINTF */ |
| 105 | |
| 106 | int (*polarssl_fprintf)( FILE *, const char *, ... ) = |
| 107 | POLARSSL_PLATFORM_STD_FPRINTF; |
| 108 | |
| 109 | int 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 */ |