blob: aeb45a537f781edc31b65595b7064b9d5d0e369d [file] [log] [blame]
Paul Bakker01cc3942012-05-08 08:36:15 +00001/*
2 * Translate error code to error string
3 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00004 * Copyright (C) 2006-2012, ARM Limited, All Rights Reserved
Paul Bakker01cc3942012-05-08 08:36:15 +00005 *
Manuel Pégourié-Gonnard967a2a52015-01-22 14:28:16 +00006 * This file is part of mbed TLS (http://www.polarssl.org)
Paul Bakker01cc3942012-05-08 08:36:15 +00007 * 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é-Gonnardcef4ad22014-04-29 12:39:06 +020026#if !defined(POLARSSL_CONFIG_FILE)
Manuel Pégourié-Gonnardabd6e022013-09-20 13:30:43 +020027#include "polarssl/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020028#else
29#include POLARSSL_CONFIG_FILE
30#endif
Paul Bakker01cc3942012-05-08 08:36:15 +000031
32#include <stdlib.h>
33#include <string.h>
34#include <stdio.h>
35
Paul Bakker01cc3942012-05-08 08:36:15 +000036#include "polarssl/error.h"
37
38#define USAGE \
Paul Bakker62534dd2013-06-30 12:45:07 +020039 "\n usage: strerror <errorcode>\n" \
40 "\n where <errorcode> can be a decimal or hexadecimal (starts with 0x or -0x)\n"
Paul Bakker01cc3942012-05-08 08:36:15 +000041
Paul Bakker8fe40dc2013-02-02 12:43:08 +010042#if !defined(POLARSSL_ERROR_C) && !defined(POLARSSL_ERROR_STRERROR_DUMMY)
Paul Bakker01cc3942012-05-08 08:36:15 +000043int main( int argc, char *argv[] )
44{
45 ((void) argc);
46 ((void) argv);
47
Paul Bakker62534dd2013-06-30 12:45:07 +020048 printf("POLARSSL_ERROR_C and/or POLARSSL_ERROR_STRERROR_DUMMY not defined.\n");
Paul Bakker01cc3942012-05-08 08:36:15 +000049 return( 0 );
50}
51#else
52int main( int argc, char *argv[] )
53{
Paul Bakker62534dd2013-06-30 12:45:07 +020054 long int val;
55 char *end = argv[1];
Paul Bakker01cc3942012-05-08 08:36:15 +000056
57 if( argc != 2 )
58 {
59 printf( USAGE );
60 return( 0 );
61 }
62
Paul Bakker62534dd2013-06-30 12:45:07 +020063 val = strtol( argv[1], &end, 10 );
64 if( *end != '\0' )
65 {
66 val = strtol( argv[1], &end, 16 );
67 if( *end != '\0' )
68 {
69 printf( USAGE );
70 return( 0 );
71 }
72 }
73 if( val > 0 )
74 val = -val;
Paul Bakker01cc3942012-05-08 08:36:15 +000075
Paul Bakker62534dd2013-06-30 12:45:07 +020076 if( val != 0 )
Paul Bakker01cc3942012-05-08 08:36:15 +000077 {
78 char error_buf[200];
Paul Bakker62534dd2013-06-30 12:45:07 +020079 polarssl_strerror( val, error_buf, 200 );
80 printf("Last error was: -0x%04x - %s\n\n", (int) -val, error_buf );
Paul Bakker01cc3942012-05-08 08:36:15 +000081 }
82
83#if defined(_WIN32)
84 printf( " + Press Enter to exit this program.\n" );
85 fflush( stdout ); getchar();
86#endif
87
Paul Bakker62534dd2013-06-30 12:45:07 +020088 return( val );
Paul Bakker01cc3942012-05-08 08:36:15 +000089}
90#endif /* POLARSSL_ERROR_C */