blob: b5dd4d144b61a4cab2da87f3308c86d907908598 [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 */
Paul Bakker747a83a2014-02-01 22:50:07 +010044#endif /* POLARSSL_CONFIG_OPTIONS */
45
46/*
47 * The function pointers for malloc and free
48 */
Paul Bakkera9066cf2014-02-05 15:13:04 +010049#if defined(POLARSSL_PLATFORM_MEMORY)
Paul Bakkerdefc0ca2014-02-04 17:30:24 +010050extern void * (*polarssl_malloc)( size_t len );
51extern void (*polarssl_free)( void *ptr );
52
53/**
54 * \brief Set your own memory implementation function pointers
55 *
56 * \param malloc_func the malloc function implementation
57 * \param free_func the free function implementation
58 *
59 * \return 0 if successful
60 */
61int platform_set_malloc_free( void * (*malloc_func)( size_t ),
62 void (*free_func)( void * ) );
Paul Bakker747a83a2014-02-01 22:50:07 +010063#else
Paul Bakker747a83a2014-02-01 22:50:07 +010064#define polarssl_malloc malloc
65#define polarssl_free free
66#endif
67
68/*
69 * The function pointers for printf
70 */
71#if defined(POLARSSL_PLATFORM_PRINTF_ALT)
72extern int (*polarssl_printf)( const char *format, ... );
73
74/**
75 * \brief Set your own printf function pointer
76 *
77 * \param printf_func the printf function implementation
78 *
79 * \return 0
80 */
81int platform_set_printf( int (*printf_func)( const char *, ... ) );
82#else
83#define polarssl_printf printf
84#endif
85
86/*
87 * The function pointers for fprintf
88 */
89#if defined(POLARSSL_PLATFORM_FPRINTF_ALT)
90extern int (*polarssl_fprintf)( FILE *stream, const char *format, ... );
91
92int platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
93 ... ) );
94#else
95#define polarssl_fprintf fprintf
96#endif
97
98#ifdef __cplusplus
99}
100#endif
101
102#endif /* platform.h */