blob: 79eec1828180c93c463b4f08d3ae8500f407357a [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é-Gonnard085ab042015-01-23 11:06:27 +00006 * This file is part of mbed TLS (https://www.polarssl.org)
Paul Bakker01cc3942012-05-08 08:36:15 +00007 *
Paul Bakker01cc3942012-05-08 08:36:15 +00008 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020023#if !defined(POLARSSL_CONFIG_FILE)
Manuel Pégourié-Gonnardabd6e022013-09-20 13:30:43 +020024#include "polarssl/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020025#else
26#include POLARSSL_CONFIG_FILE
27#endif
Paul Bakker01cc3942012-05-08 08:36:15 +000028
29#include <stdlib.h>
30#include <string.h>
31#include <stdio.h>
32
Paul Bakker01cc3942012-05-08 08:36:15 +000033#include "polarssl/error.h"
34
35#define USAGE \
Paul Bakker62534dd2013-06-30 12:45:07 +020036 "\n usage: strerror <errorcode>\n" \
37 "\n where <errorcode> can be a decimal or hexadecimal (starts with 0x or -0x)\n"
Paul Bakker01cc3942012-05-08 08:36:15 +000038
Paul Bakker8fe40dc2013-02-02 12:43:08 +010039#if !defined(POLARSSL_ERROR_C) && !defined(POLARSSL_ERROR_STRERROR_DUMMY)
Paul Bakker01cc3942012-05-08 08:36:15 +000040int main( int argc, char *argv[] )
41{
42 ((void) argc);
43 ((void) argv);
44
Paul Bakker62534dd2013-06-30 12:45:07 +020045 printf("POLARSSL_ERROR_C and/or POLARSSL_ERROR_STRERROR_DUMMY not defined.\n");
Paul Bakker01cc3942012-05-08 08:36:15 +000046 return( 0 );
47}
48#else
49int main( int argc, char *argv[] )
50{
Paul Bakker62534dd2013-06-30 12:45:07 +020051 long int val;
52 char *end = argv[1];
Paul Bakker01cc3942012-05-08 08:36:15 +000053
54 if( argc != 2 )
55 {
56 printf( USAGE );
57 return( 0 );
58 }
59
Paul Bakker62534dd2013-06-30 12:45:07 +020060 val = strtol( argv[1], &end, 10 );
61 if( *end != '\0' )
62 {
63 val = strtol( argv[1], &end, 16 );
64 if( *end != '\0' )
65 {
66 printf( USAGE );
67 return( 0 );
68 }
69 }
70 if( val > 0 )
71 val = -val;
Paul Bakker01cc3942012-05-08 08:36:15 +000072
Paul Bakker62534dd2013-06-30 12:45:07 +020073 if( val != 0 )
Paul Bakker01cc3942012-05-08 08:36:15 +000074 {
75 char error_buf[200];
Paul Bakker62534dd2013-06-30 12:45:07 +020076 polarssl_strerror( val, error_buf, 200 );
77 printf("Last error was: -0x%04x - %s\n\n", (int) -val, error_buf );
Paul Bakker01cc3942012-05-08 08:36:15 +000078 }
79
80#if defined(_WIN32)
81 printf( " + Press Enter to exit this program.\n" );
82 fflush( stdout ); getchar();
83#endif
84
Paul Bakker62534dd2013-06-30 12:45:07 +020085 return( val );
Paul Bakker01cc3942012-05-08 08:36:15 +000086}
87#endif /* POLARSSL_ERROR_C */