This is a fork due to permission issues

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of 6_songs-from-the-cloud by MakingMusicWorkshop

Committer:
maclobdell
Date:
Wed May 18 19:06:32 2016 +0000
Revision:
0:f7c60d3e7b8a
clean version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maclobdell 0:f7c60d3e7b8a 1 /*
maclobdell 0:f7c60d3e7b8a 2 * Platform abstraction layer
maclobdell 0:f7c60d3e7b8a 3 *
maclobdell 0:f7c60d3e7b8a 4 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
maclobdell 0:f7c60d3e7b8a 5 * SPDX-License-Identifier: Apache-2.0
maclobdell 0:f7c60d3e7b8a 6 *
maclobdell 0:f7c60d3e7b8a 7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
maclobdell 0:f7c60d3e7b8a 8 * not use this file except in compliance with the License.
maclobdell 0:f7c60d3e7b8a 9 * You may obtain a copy of the License at
maclobdell 0:f7c60d3e7b8a 10 *
maclobdell 0:f7c60d3e7b8a 11 * http://www.apache.org/licenses/LICENSE-2.0
maclobdell 0:f7c60d3e7b8a 12 *
maclobdell 0:f7c60d3e7b8a 13 * Unless required by applicable law or agreed to in writing, software
maclobdell 0:f7c60d3e7b8a 14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
maclobdell 0:f7c60d3e7b8a 15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
maclobdell 0:f7c60d3e7b8a 16 * See the License for the specific language governing permissions and
maclobdell 0:f7c60d3e7b8a 17 * limitations under the License.
maclobdell 0:f7c60d3e7b8a 18 *
maclobdell 0:f7c60d3e7b8a 19 * This file is part of mbed TLS (https://tls.mbed.org)
maclobdell 0:f7c60d3e7b8a 20 */
maclobdell 0:f7c60d3e7b8a 21
maclobdell 0:f7c60d3e7b8a 22 #if !defined(MBEDTLS_CONFIG_FILE)
maclobdell 0:f7c60d3e7b8a 23 #include "mbedtls/config.h"
maclobdell 0:f7c60d3e7b8a 24 #else
maclobdell 0:f7c60d3e7b8a 25 #include MBEDTLS_CONFIG_FILE
maclobdell 0:f7c60d3e7b8a 26 #endif
maclobdell 0:f7c60d3e7b8a 27
maclobdell 0:f7c60d3e7b8a 28 #if defined(MBEDTLS_PLATFORM_C)
maclobdell 0:f7c60d3e7b8a 29
maclobdell 0:f7c60d3e7b8a 30 #include "mbedtls/platform.h"
maclobdell 0:f7c60d3e7b8a 31
maclobdell 0:f7c60d3e7b8a 32 #if defined(MBEDTLS_PLATFORM_MEMORY)
maclobdell 0:f7c60d3e7b8a 33 #if !defined(MBEDTLS_PLATFORM_STD_CALLOC)
maclobdell 0:f7c60d3e7b8a 34 static void *platform_calloc_uninit( size_t n, size_t size )
maclobdell 0:f7c60d3e7b8a 35 {
maclobdell 0:f7c60d3e7b8a 36 ((void) n);
maclobdell 0:f7c60d3e7b8a 37 ((void) size);
maclobdell 0:f7c60d3e7b8a 38 return( NULL );
maclobdell 0:f7c60d3e7b8a 39 }
maclobdell 0:f7c60d3e7b8a 40
maclobdell 0:f7c60d3e7b8a 41 #define MBEDTLS_PLATFORM_STD_CALLOC platform_calloc_uninit
maclobdell 0:f7c60d3e7b8a 42 #endif /* !MBEDTLS_PLATFORM_STD_CALLOC */
maclobdell 0:f7c60d3e7b8a 43
maclobdell 0:f7c60d3e7b8a 44 #if !defined(MBEDTLS_PLATFORM_STD_FREE)
maclobdell 0:f7c60d3e7b8a 45 static void platform_free_uninit( void *ptr )
maclobdell 0:f7c60d3e7b8a 46 {
maclobdell 0:f7c60d3e7b8a 47 ((void) ptr);
maclobdell 0:f7c60d3e7b8a 48 }
maclobdell 0:f7c60d3e7b8a 49
maclobdell 0:f7c60d3e7b8a 50 #define MBEDTLS_PLATFORM_STD_FREE platform_free_uninit
maclobdell 0:f7c60d3e7b8a 51 #endif /* !MBEDTLS_PLATFORM_STD_FREE */
maclobdell 0:f7c60d3e7b8a 52
maclobdell 0:f7c60d3e7b8a 53 void * (*mbedtls_calloc)( size_t, size_t ) = MBEDTLS_PLATFORM_STD_CALLOC;
maclobdell 0:f7c60d3e7b8a 54 void (*mbedtls_free)( void * ) = MBEDTLS_PLATFORM_STD_FREE;
maclobdell 0:f7c60d3e7b8a 55
maclobdell 0:f7c60d3e7b8a 56 int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ),
maclobdell 0:f7c60d3e7b8a 57 void (*free_func)( void * ) )
maclobdell 0:f7c60d3e7b8a 58 {
maclobdell 0:f7c60d3e7b8a 59 mbedtls_calloc = calloc_func;
maclobdell 0:f7c60d3e7b8a 60 mbedtls_free = free_func;
maclobdell 0:f7c60d3e7b8a 61 return( 0 );
maclobdell 0:f7c60d3e7b8a 62 }
maclobdell 0:f7c60d3e7b8a 63 #endif /* MBEDTLS_PLATFORM_MEMORY */
maclobdell 0:f7c60d3e7b8a 64
maclobdell 0:f7c60d3e7b8a 65 #if defined(_WIN32)
maclobdell 0:f7c60d3e7b8a 66 #include <stdarg.h>
maclobdell 0:f7c60d3e7b8a 67 int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... )
maclobdell 0:f7c60d3e7b8a 68 {
maclobdell 0:f7c60d3e7b8a 69 int ret;
maclobdell 0:f7c60d3e7b8a 70 va_list argp;
maclobdell 0:f7c60d3e7b8a 71
maclobdell 0:f7c60d3e7b8a 72 /* Avoid calling the invalid parameter handler by checking ourselves */
maclobdell 0:f7c60d3e7b8a 73 if( s == NULL || n == 0 || fmt == NULL )
maclobdell 0:f7c60d3e7b8a 74 return( -1 );
maclobdell 0:f7c60d3e7b8a 75
maclobdell 0:f7c60d3e7b8a 76 va_start( argp, fmt );
maclobdell 0:f7c60d3e7b8a 77 #if defined(_TRUNCATE)
maclobdell 0:f7c60d3e7b8a 78 ret = _vsnprintf_s( s, n, _TRUNCATE, fmt, argp );
maclobdell 0:f7c60d3e7b8a 79 #else
maclobdell 0:f7c60d3e7b8a 80 ret = _vsnprintf( s, n, fmt, argp );
maclobdell 0:f7c60d3e7b8a 81 if( ret < 0 || (size_t) ret == n )
maclobdell 0:f7c60d3e7b8a 82 {
maclobdell 0:f7c60d3e7b8a 83 s[n-1] = '\0';
maclobdell 0:f7c60d3e7b8a 84 ret = -1;
maclobdell 0:f7c60d3e7b8a 85 }
maclobdell 0:f7c60d3e7b8a 86 #endif
maclobdell 0:f7c60d3e7b8a 87 va_end( argp );
maclobdell 0:f7c60d3e7b8a 88
maclobdell 0:f7c60d3e7b8a 89 return( ret );
maclobdell 0:f7c60d3e7b8a 90 }
maclobdell 0:f7c60d3e7b8a 91 #endif
maclobdell 0:f7c60d3e7b8a 92
maclobdell 0:f7c60d3e7b8a 93 #if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
maclobdell 0:f7c60d3e7b8a 94 #if !defined(MBEDTLS_PLATFORM_STD_SNPRINTF)
maclobdell 0:f7c60d3e7b8a 95 /*
maclobdell 0:f7c60d3e7b8a 96 * Make dummy function to prevent NULL pointer dereferences
maclobdell 0:f7c60d3e7b8a 97 */
maclobdell 0:f7c60d3e7b8a 98 static int platform_snprintf_uninit( char * s, size_t n,
maclobdell 0:f7c60d3e7b8a 99 const char * format, ... )
maclobdell 0:f7c60d3e7b8a 100 {
maclobdell 0:f7c60d3e7b8a 101 ((void) s);
maclobdell 0:f7c60d3e7b8a 102 ((void) n);
maclobdell 0:f7c60d3e7b8a 103 ((void) format);
maclobdell 0:f7c60d3e7b8a 104 return( 0 );
maclobdell 0:f7c60d3e7b8a 105 }
maclobdell 0:f7c60d3e7b8a 106
maclobdell 0:f7c60d3e7b8a 107 #define MBEDTLS_PLATFORM_STD_SNPRINTF platform_snprintf_uninit
maclobdell 0:f7c60d3e7b8a 108 #endif /* !MBEDTLS_PLATFORM_STD_SNPRINTF */
maclobdell 0:f7c60d3e7b8a 109
maclobdell 0:f7c60d3e7b8a 110 int (*mbedtls_snprintf)( char * s, size_t n,
maclobdell 0:f7c60d3e7b8a 111 const char * format,
maclobdell 0:f7c60d3e7b8a 112 ... ) = MBEDTLS_PLATFORM_STD_SNPRINTF;
maclobdell 0:f7c60d3e7b8a 113
maclobdell 0:f7c60d3e7b8a 114 int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
maclobdell 0:f7c60d3e7b8a 115 const char * format,
maclobdell 0:f7c60d3e7b8a 116 ... ) )
maclobdell 0:f7c60d3e7b8a 117 {
maclobdell 0:f7c60d3e7b8a 118 mbedtls_snprintf = snprintf_func;
maclobdell 0:f7c60d3e7b8a 119 return( 0 );
maclobdell 0:f7c60d3e7b8a 120 }
maclobdell 0:f7c60d3e7b8a 121 #endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
maclobdell 0:f7c60d3e7b8a 122
maclobdell 0:f7c60d3e7b8a 123 #if defined(MBEDTLS_PLATFORM_PRINTF_ALT)
maclobdell 0:f7c60d3e7b8a 124 #if !defined(MBEDTLS_PLATFORM_STD_PRINTF)
maclobdell 0:f7c60d3e7b8a 125 /*
maclobdell 0:f7c60d3e7b8a 126 * Make dummy function to prevent NULL pointer dereferences
maclobdell 0:f7c60d3e7b8a 127 */
maclobdell 0:f7c60d3e7b8a 128 static int platform_printf_uninit( const char *format, ... )
maclobdell 0:f7c60d3e7b8a 129 {
maclobdell 0:f7c60d3e7b8a 130 ((void) format);
maclobdell 0:f7c60d3e7b8a 131 return( 0 );
maclobdell 0:f7c60d3e7b8a 132 }
maclobdell 0:f7c60d3e7b8a 133
maclobdell 0:f7c60d3e7b8a 134 #define MBEDTLS_PLATFORM_STD_PRINTF platform_printf_uninit
maclobdell 0:f7c60d3e7b8a 135 #endif /* !MBEDTLS_PLATFORM_STD_PRINTF */
maclobdell 0:f7c60d3e7b8a 136
maclobdell 0:f7c60d3e7b8a 137 int (*mbedtls_printf)( const char *, ... ) = MBEDTLS_PLATFORM_STD_PRINTF;
maclobdell 0:f7c60d3e7b8a 138
maclobdell 0:f7c60d3e7b8a 139 int mbedtls_platform_set_printf( int (*printf_func)( const char *, ... ) )
maclobdell 0:f7c60d3e7b8a 140 {
maclobdell 0:f7c60d3e7b8a 141 mbedtls_printf = printf_func;
maclobdell 0:f7c60d3e7b8a 142 return( 0 );
maclobdell 0:f7c60d3e7b8a 143 }
maclobdell 0:f7c60d3e7b8a 144 #endif /* MBEDTLS_PLATFORM_PRINTF_ALT */
maclobdell 0:f7c60d3e7b8a 145
maclobdell 0:f7c60d3e7b8a 146 #if defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
maclobdell 0:f7c60d3e7b8a 147 #if !defined(MBEDTLS_PLATFORM_STD_FPRINTF)
maclobdell 0:f7c60d3e7b8a 148 /*
maclobdell 0:f7c60d3e7b8a 149 * Make dummy function to prevent NULL pointer dereferences
maclobdell 0:f7c60d3e7b8a 150 */
maclobdell 0:f7c60d3e7b8a 151 static int platform_fprintf_uninit( FILE *stream, const char *format, ... )
maclobdell 0:f7c60d3e7b8a 152 {
maclobdell 0:f7c60d3e7b8a 153 ((void) stream);
maclobdell 0:f7c60d3e7b8a 154 ((void) format);
maclobdell 0:f7c60d3e7b8a 155 return( 0 );
maclobdell 0:f7c60d3e7b8a 156 }
maclobdell 0:f7c60d3e7b8a 157
maclobdell 0:f7c60d3e7b8a 158 #define MBEDTLS_PLATFORM_STD_FPRINTF platform_fprintf_uninit
maclobdell 0:f7c60d3e7b8a 159 #endif /* !MBEDTLS_PLATFORM_STD_FPRINTF */
maclobdell 0:f7c60d3e7b8a 160
maclobdell 0:f7c60d3e7b8a 161 int (*mbedtls_fprintf)( FILE *, const char *, ... ) =
maclobdell 0:f7c60d3e7b8a 162 MBEDTLS_PLATFORM_STD_FPRINTF;
maclobdell 0:f7c60d3e7b8a 163
maclobdell 0:f7c60d3e7b8a 164 int mbedtls_platform_set_fprintf( int (*fprintf_func)( FILE *, const char *, ... ) )
maclobdell 0:f7c60d3e7b8a 165 {
maclobdell 0:f7c60d3e7b8a 166 mbedtls_fprintf = fprintf_func;
maclobdell 0:f7c60d3e7b8a 167 return( 0 );
maclobdell 0:f7c60d3e7b8a 168 }
maclobdell 0:f7c60d3e7b8a 169 #endif /* MBEDTLS_PLATFORM_FPRINTF_ALT */
maclobdell 0:f7c60d3e7b8a 170
maclobdell 0:f7c60d3e7b8a 171 #if defined(MBEDTLS_PLATFORM_EXIT_ALT)
maclobdell 0:f7c60d3e7b8a 172 #if !defined(MBEDTLS_PLATFORM_STD_EXIT)
maclobdell 0:f7c60d3e7b8a 173 /*
maclobdell 0:f7c60d3e7b8a 174 * Make dummy function to prevent NULL pointer dereferences
maclobdell 0:f7c60d3e7b8a 175 */
maclobdell 0:f7c60d3e7b8a 176 static void platform_exit_uninit( int status )
maclobdell 0:f7c60d3e7b8a 177 {
maclobdell 0:f7c60d3e7b8a 178 ((void) status);
maclobdell 0:f7c60d3e7b8a 179 }
maclobdell 0:f7c60d3e7b8a 180
maclobdell 0:f7c60d3e7b8a 181 #define MBEDTLS_PLATFORM_STD_EXIT platform_exit_uninit
maclobdell 0:f7c60d3e7b8a 182 #endif /* !MBEDTLS_PLATFORM_STD_EXIT */
maclobdell 0:f7c60d3e7b8a 183
maclobdell 0:f7c60d3e7b8a 184 void (*mbedtls_exit)( int status ) = MBEDTLS_PLATFORM_STD_EXIT;
maclobdell 0:f7c60d3e7b8a 185
maclobdell 0:f7c60d3e7b8a 186 int mbedtls_platform_set_exit( void (*exit_func)( int status ) )
maclobdell 0:f7c60d3e7b8a 187 {
maclobdell 0:f7c60d3e7b8a 188 mbedtls_exit = exit_func;
maclobdell 0:f7c60d3e7b8a 189 return( 0 );
maclobdell 0:f7c60d3e7b8a 190 }
maclobdell 0:f7c60d3e7b8a 191 #endif /* MBEDTLS_PLATFORM_EXIT_ALT */
maclobdell 0:f7c60d3e7b8a 192
maclobdell 0:f7c60d3e7b8a 193 #endif /* MBEDTLS_PLATFORM_C */