blob: 08832b3c3d221048b46d9a89b96697a129453569 [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)
39#define POLARSSL_PLATFORM_STD_PRINTF printf /**< Default printf to use */
40#define POLARSSL_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use */
Paul Bakkerdefc0ca2014-02-04 17:30:24 +010041#define POLARSSL_PLATFORM_STD_MALLOC malloc /**< Default allocator to use */
42#define POLARSSL_PLATFORM_STD_FREE free /**< Default free to use */
Paul Bakker747a83a2014-02-01 22:50:07 +010043#endif /* POLARSSL_CONFIG_OPTIONS */
44
45/*
46 * The function pointers for malloc and free
47 */
48#if defined(POLARSSL_MEMORY_C)
Paul Bakkerdefc0ca2014-02-04 17:30:24 +010049extern void * (*polarssl_malloc)( size_t len );
50extern void (*polarssl_free)( void *ptr );
51
52/**
53 * \brief Set your own memory implementation function pointers
54 *
55 * \param malloc_func the malloc function implementation
56 * \param free_func the free function implementation
57 *
58 * \return 0 if successful
59 */
60int platform_set_malloc_free( void * (*malloc_func)( size_t ),
61 void (*free_func)( void * ) );
Paul Bakker747a83a2014-02-01 22:50:07 +010062#else
Paul Bakkerb2f66c92014-02-04 16:27:57 +010063#include <stdlib.h>
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 */