Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file platform.h |
| 3 | * |
| 4 | * \brief PolarSSL Platform abstraction layer |
| 5 | * |
| 6 | * Copyright (C) 2006-2014, Brainspark B.V. |
| 7 | * |
| 8 | * This file is part of PolarSSL (http://www.polarssl.org) |
| 9 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
| 10 | * |
| 11 | * All rights reserved. |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2 of the License, or |
| 16 | * (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License along |
| 24 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 25 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 26 | */ |
| 27 | #ifndef POLARSSL_PLATFORM_H |
| 28 | #define POLARSSL_PLATFORM_H |
| 29 | |
| 30 | #include "config.h" |
| 31 | |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 32 | #include <stdio.h> |
| 33 | |
| 34 | #ifdef __cplusplus |
| 35 | extern "C" { |
| 36 | #endif |
| 37 | |
| 38 | #if !defined(POLARSSL_CONFIG_OPTIONS) |
Paul Bakker | a9066cf | 2014-02-05 15:13:04 +0100 | [diff] [blame] | 39 | #include <stdlib.h> |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 40 | #define POLARSSL_PLATFORM_STD_PRINTF printf /**< Default printf to use */ |
| 41 | #define POLARSSL_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use */ |
Paul Bakker | defc0ca | 2014-02-04 17:30:24 +0100 | [diff] [blame] | 42 | #define POLARSSL_PLATFORM_STD_MALLOC malloc /**< Default allocator to use */ |
| 43 | #define POLARSSL_PLATFORM_STD_FREE free /**< Default free to use */ |
Manuel Pégourié-Gonnard | eb82a74 | 2014-04-02 13:43:48 +0200 | [diff] [blame^] | 44 | #else /* POLARSSL_CONFIG_OPTIONS */ |
| 45 | #if defined(POLARSSL_PLATFORM_STD_MEM_HDR) |
| 46 | #include POLARSSL_PLATFORM_STD_MEM_HDR |
| 47 | #endif |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 48 | #endif /* POLARSSL_CONFIG_OPTIONS */ |
| 49 | |
| 50 | /* |
| 51 | * The function pointers for malloc and free |
| 52 | */ |
Paul Bakker | a9066cf | 2014-02-05 15:13:04 +0100 | [diff] [blame] | 53 | #if defined(POLARSSL_PLATFORM_MEMORY) |
Paul Bakker | defc0ca | 2014-02-04 17:30:24 +0100 | [diff] [blame] | 54 | extern void * (*polarssl_malloc)( size_t len ); |
| 55 | extern void (*polarssl_free)( void *ptr ); |
| 56 | |
| 57 | /** |
| 58 | * \brief Set your own memory implementation function pointers |
| 59 | * |
| 60 | * \param malloc_func the malloc function implementation |
| 61 | * \param free_func the free function implementation |
| 62 | * |
| 63 | * \return 0 if successful |
| 64 | */ |
| 65 | int platform_set_malloc_free( void * (*malloc_func)( size_t ), |
| 66 | void (*free_func)( void * ) ); |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 67 | #else |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 68 | #define polarssl_malloc malloc |
| 69 | #define polarssl_free free |
| 70 | #endif |
| 71 | |
| 72 | /* |
| 73 | * The function pointers for printf |
| 74 | */ |
| 75 | #if defined(POLARSSL_PLATFORM_PRINTF_ALT) |
| 76 | extern int (*polarssl_printf)( const char *format, ... ); |
| 77 | |
| 78 | /** |
| 79 | * \brief Set your own printf function pointer |
| 80 | * |
| 81 | * \param printf_func the printf function implementation |
| 82 | * |
| 83 | * \return 0 |
| 84 | */ |
| 85 | int platform_set_printf( int (*printf_func)( const char *, ... ) ); |
| 86 | #else |
| 87 | #define polarssl_printf printf |
| 88 | #endif |
| 89 | |
| 90 | /* |
| 91 | * The function pointers for fprintf |
| 92 | */ |
| 93 | #if defined(POLARSSL_PLATFORM_FPRINTF_ALT) |
| 94 | extern int (*polarssl_fprintf)( FILE *stream, const char *format, ... ); |
| 95 | |
| 96 | int platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *, |
| 97 | ... ) ); |
| 98 | #else |
| 99 | #define polarssl_fprintf fprintf |
| 100 | #endif |
| 101 | |
| 102 | #ifdef __cplusplus |
| 103 | } |
| 104 | #endif |
| 105 | |
| 106 | #endif /* platform.h */ |