blob: a202ac15d22223fb92eb96368f463236c68cb317 [file] [log] [blame]
Paul Bakker747a83a2014-02-01 22:50:07 +01001/**
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 Bakker747a83a2014-02-01 22:50:07 +010032#include <stdio.h>
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38#if !defined(POLARSSL_CONFIG_OPTIONS)
Paul Bakkera9066cf2014-02-05 15:13:04 +010039#include <stdlib.h>
Paul Bakker747a83a2014-02-01 22:50:07 +010040#define POLARSSL_PLATFORM_STD_PRINTF printf /**< Default printf to use */
41#define POLARSSL_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use */
Paul Bakkerdefc0ca2014-02-04 17:30:24 +010042#define POLARSSL_PLATFORM_STD_MALLOC malloc /**< Default allocator to use */
43#define POLARSSL_PLATFORM_STD_FREE free /**< Default free to use */
Manuel Pégourié-Gonnardeb82a742014-04-02 13:43:48 +020044#else /* POLARSSL_CONFIG_OPTIONS */
45#if defined(POLARSSL_PLATFORM_STD_MEM_HDR)
46#include POLARSSL_PLATFORM_STD_MEM_HDR
47#endif
Paul Bakker747a83a2014-02-01 22:50:07 +010048#endif /* POLARSSL_CONFIG_OPTIONS */
49
50/*
51 * The function pointers for malloc and free
52 */
Paul Bakkera9066cf2014-02-05 15:13:04 +010053#if defined(POLARSSL_PLATFORM_MEMORY)
Paul Bakkerdefc0ca2014-02-04 17:30:24 +010054extern void * (*polarssl_malloc)( size_t len );
55extern 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 */
65int platform_set_malloc_free( void * (*malloc_func)( size_t ),
66 void (*free_func)( void * ) );
Paul Bakker747a83a2014-02-01 22:50:07 +010067#else
Paul Bakker747a83a2014-02-01 22:50:07 +010068#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)
76extern 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 */
85int 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)
94extern int (*polarssl_fprintf)( FILE *stream, const char *format, ... );
95
96int 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 */