2 * Error message information
4 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
5 * SPDX-License-Identifier: Apache-2.0
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * This file is part of mbed TLS (https://tls.mbed.org)
22 #if !defined(MBEDTLS_CONFIG_FILE)
23 #include "mbedtls/config.h"
25 #include MBEDTLS_CONFIG_FILE
28 #if defined(MBEDTLS_ERROR_C) || defined(MBEDTLS_ERROR_STRERROR_DUMMY)
29 #include "mbedtls/error.h"
33 #if defined(MBEDTLS_PLATFORM_C)
34 #include "mbedtls/platform.h"
36 #define mbedtls_snprintf snprintf
37 #define mbedtls_time_t time_t
40 #if defined(MBEDTLS_ERROR_C)
46 void mbedtls_strerror( int ret, char *buf, size_t buflen )
54 memset( buf, 0x00, buflen );
61 use_ret = ret & 0xFF80;
63 // High level error codes
65 // BEGIN generated code
66 HIGH_LEVEL_CODE_CHECKS
69 if( strlen( buf ) == 0 )
70 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
73 use_ret = ret & ~0xFF80;
78 // If high level code is present, make a concatenation between both
85 if( buflen - len < 5 )
88 mbedtls_snprintf( buf + len, buflen - len, " : " );
94 // Low level error codes
96 // BEGIN generated code
100 if( strlen( buf ) != 0 )
103 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
106 #else /* MBEDTLS_ERROR_C */
108 #if defined(MBEDTLS_ERROR_STRERROR_DUMMY)
111 * Provide an non-function in case MBEDTLS_ERROR_C is not defined
113 void mbedtls_strerror( int ret, char *buf, size_t buflen )
121 #endif /* MBEDTLS_ERROR_STRERROR_DUMMY */
123 #endif /* MBEDTLS_ERROR_C */