blob: 91f5c9e678db624953e4c0f2e179fe87d6b526f6 [file] [log] [blame]
Paul Bakker01cc3942012-05-08 08:36:15 +00001/*
2 * Translate error code to error string
3 *
4 * Copyright (C) 2006-2012, 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
Manuel Pégourié-Gonnardabd6e022013-09-20 13:30:43 +020026#include "polarssl/config.h"
Paul Bakker01cc3942012-05-08 08:36:15 +000027
28#include <stdlib.h>
29#include <string.h>
30#include <stdio.h>
31
Paul Bakker01cc3942012-05-08 08:36:15 +000032#include "polarssl/error.h"
33
34#define USAGE \
Paul Bakker62534dd2013-06-30 12:45:07 +020035 "\n usage: strerror <errorcode>\n" \
36 "\n where <errorcode> can be a decimal or hexadecimal (starts with 0x or -0x)\n"
Paul Bakker01cc3942012-05-08 08:36:15 +000037
Paul Bakker8fe40dc2013-02-02 12:43:08 +010038#if !defined(POLARSSL_ERROR_C) && !defined(POLARSSL_ERROR_STRERROR_DUMMY)
Paul Bakker01cc3942012-05-08 08:36:15 +000039int main( int argc, char *argv[] )
40{
41 ((void) argc);
42 ((void) argv);
43
Paul Bakker62534dd2013-06-30 12:45:07 +020044 printf("POLARSSL_ERROR_C and/or POLARSSL_ERROR_STRERROR_DUMMY not defined.\n");
Paul Bakker01cc3942012-05-08 08:36:15 +000045 return( 0 );
46}
47#else
48int main( int argc, char *argv[] )
49{
Paul Bakker62534dd2013-06-30 12:45:07 +020050 long int val;
51 char *end = argv[1];
Paul Bakker01cc3942012-05-08 08:36:15 +000052
53 if( argc != 2 )
54 {
55 printf( USAGE );
56 return( 0 );
57 }
58
Paul Bakker62534dd2013-06-30 12:45:07 +020059 val = strtol( argv[1], &end, 10 );
60 if( *end != '\0' )
61 {
62 val = strtol( argv[1], &end, 16 );
63 if( *end != '\0' )
64 {
65 printf( USAGE );
66 return( 0 );
67 }
68 }
69 if( val > 0 )
70 val = -val;
Paul Bakker01cc3942012-05-08 08:36:15 +000071
Paul Bakker62534dd2013-06-30 12:45:07 +020072 if( val != 0 )
Paul Bakker01cc3942012-05-08 08:36:15 +000073 {
74 char error_buf[200];
Paul Bakker62534dd2013-06-30 12:45:07 +020075 polarssl_strerror( val, error_buf, 200 );
76 printf("Last error was: -0x%04x - %s\n\n", (int) -val, error_buf );
Paul Bakker01cc3942012-05-08 08:36:15 +000077 }
78
79#if defined(_WIN32)
80 printf( " + Press Enter to exit this program.\n" );
81 fflush( stdout ); getchar();
82#endif
83
Paul Bakker62534dd2013-06-30 12:45:07 +020084 return( val );
Paul Bakker01cc3942012-05-08 08:36:15 +000085}
86#endif /* POLARSSL_ERROR_C */