blob: e9dd74124544d2c144b78ec345c659dee44ce233 [file] [log] [blame]
Paul Bakker9d781402011-05-09 16:17:09 +00001/*
2 * Error message information
3 *
4 * Copyright (C) 2006-2010, Brainspark B.V.
5 *
6 * This file is part of PolarSSL (http://www.polarssl.org)
7 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
8 *
9 * All rights reserved.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 */
25
26#include "polarssl/config.h"
27
28#if defined(POLARSSL_ERROR_C)
29
30HEADER_INCLUDED
31
32#include <string.h>
33
34void error_strerror( int ret, char *buf, size_t buflen )
35{
36 size_t len;
37 int use_ret;
38
39 memset( buf, 0x00, buflen );
40
41 if( ret < 0 )
42 ret = -ret;
43
44 if( ret & 0xFF80 )
45 {
46 use_ret = ret & 0xFF80;
47
48 // High level error codes
49 //
50HIGH_LEVEL_CODE_CHECKS
51 if( strlen( buf ) == 0 )
52 snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
53 }
54
55 use_ret = ret & ~0xFF80;
56
57 if( use_ret == 0 )
58 return;
59
60 // If high level code is present, make a concatenation between both
61 // error strings.
62 //
63 len = strlen( buf );
64
65 if( len > 0 )
66 {
67 if( buflen - len < 5 )
68 return;
69
70 snprintf( buf + len, buflen - len, " : " );
71
72 buf += len + 3;
73 buflen -= len + 3;
74 }
75
76 // Low level error codes
77 //
78LOW_LEVEL_CODE_CHECKS
79 if( strlen( buf ) != 0 )
80 return;
81
82 snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
83}
84
85#endif /* POLARSSL_VERBOSE_ERROR */