blob: b61aad021b2d4733ea8fd294a8d0956f8721201c [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
Paul Bakker088c5c52014-04-25 11:11:10 +020038/**
39 * \name SECTION: Module settings
40 *
41 * The configuration options you can set for this module are in this section.
42 * Either change them in config.h or define them on the compiler command line.
43 * \{
44 */
45
46#if !defined(POLARSSL_PLATFORM_NO_STD_FUNCTIONS)
Paul Bakkera9066cf2014-02-05 15:13:04 +010047#include <stdlib.h>
Paul Bakker088c5c52014-04-25 11:11:10 +020048#if !defined(POLARSSL_PLATFORM_STD_PRINTF)
Paul Bakker747a83a2014-02-01 22:50:07 +010049#define POLARSSL_PLATFORM_STD_PRINTF printf /**< Default printf to use */
Paul Bakker088c5c52014-04-25 11:11:10 +020050#endif
51#if !defined(POLARSSL_PLATFORM_STD_FPRINTF)
Paul Bakker747a83a2014-02-01 22:50:07 +010052#define POLARSSL_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use */
Paul Bakker088c5c52014-04-25 11:11:10 +020053#endif
54#if !defined(POLARSSL_PLATFORM_STD_MALLOC)
Paul Bakkerdefc0ca2014-02-04 17:30:24 +010055#define POLARSSL_PLATFORM_STD_MALLOC malloc /**< Default allocator to use */
Paul Bakker088c5c52014-04-25 11:11:10 +020056#endif
57#if !defined(POLARSSL_PLATFORM_STD_FREE)
Paul Bakkerdefc0ca2014-02-04 17:30:24 +010058#define POLARSSL_PLATFORM_STD_FREE free /**< Default free to use */
Paul Bakker088c5c52014-04-25 11:11:10 +020059#endif
60#else /* POLARSSL_PLATFORM_NO_STD_FUNCTIONS */
Manuel Pégourié-Gonnardeb82a742014-04-02 13:43:48 +020061#if defined(POLARSSL_PLATFORM_STD_MEM_HDR)
62#include POLARSSL_PLATFORM_STD_MEM_HDR
63#endif
Paul Bakker088c5c52014-04-25 11:11:10 +020064#endif /* POLARSSL_PLATFORM_NO_STD_FUNCTIONS */
65
66/* \} name SECTION: Module settings */
Paul Bakker747a83a2014-02-01 22:50:07 +010067
68/*
69 * The function pointers for malloc and free
70 */
Paul Bakkera9066cf2014-02-05 15:13:04 +010071#if defined(POLARSSL_PLATFORM_MEMORY)
Paul Bakkerdefc0ca2014-02-04 17:30:24 +010072extern void * (*polarssl_malloc)( size_t len );
73extern void (*polarssl_free)( void *ptr );
74
75/**
76 * \brief Set your own memory implementation function pointers
77 *
78 * \param malloc_func the malloc function implementation
79 * \param free_func the free function implementation
80 *
81 * \return 0 if successful
82 */
83int platform_set_malloc_free( void * (*malloc_func)( size_t ),
84 void (*free_func)( void * ) );
Paul Bakker747a83a2014-02-01 22:50:07 +010085#else
Paul Bakker747a83a2014-02-01 22:50:07 +010086#define polarssl_malloc malloc
87#define polarssl_free free
88#endif
89
90/*
91 * The function pointers for printf
92 */
93#if defined(POLARSSL_PLATFORM_PRINTF_ALT)
94extern int (*polarssl_printf)( const char *format, ... );
95
96/**
97 * \brief Set your own printf function pointer
98 *
99 * \param printf_func the printf function implementation
100 *
101 * \return 0
102 */
103int platform_set_printf( int (*printf_func)( const char *, ... ) );
104#else
105#define polarssl_printf printf
106#endif
107
108/*
109 * The function pointers for fprintf
110 */
111#if defined(POLARSSL_PLATFORM_FPRINTF_ALT)
112extern int (*polarssl_fprintf)( FILE *stream, const char *format, ... );
113
114int platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
115 ... ) );
116#else
117#define polarssl_fprintf fprintf
118#endif
119
120#ifdef __cplusplus
121}
122#endif
123
124#endif /* platform.h */