Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Translate error code to error string |
| 3 | * |
Manuel Pégourié-Gonnard | a658a40 | 2015-01-23 09:45:19 +0000 | [diff] [blame] | 4 | * Copyright (C) 2006-2012, ARM Limited, All Rights Reserved |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 5 | * |
Manuel Pégourié-Gonnard | 085ab04 | 2015-01-23 11:06:27 +0000 | [diff] [blame] | 6 | * This file is part of mbed TLS (https://www.polarssl.org) |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 7 | * |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 8 | * 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é-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 23 | #if !defined(POLARSSL_CONFIG_FILE) |
Manuel Pégourié-Gonnard | abd6e02 | 2013-09-20 13:30:43 +0200 | [diff] [blame] | 24 | #include "polarssl/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 25 | #else |
| 26 | #include POLARSSL_CONFIG_FILE |
| 27 | #endif |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 28 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 29 | #if defined(POLARSSL_PLATFORM_C) |
| 30 | #include "polarssl/platform.h" |
| 31 | #else |
| 32 | #define polarssl_printf printf |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 33 | #endif |
| 34 | |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 35 | #include <stdlib.h> |
| 36 | #include <string.h> |
| 37 | #include <stdio.h> |
| 38 | |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 39 | #include "polarssl/error.h" |
| 40 | |
| 41 | #define USAGE \ |
Paul Bakker | 62534dd | 2013-06-30 12:45:07 +0200 | [diff] [blame] | 42 | "\n usage: strerror <errorcode>\n" \ |
| 43 | "\n where <errorcode> can be a decimal or hexadecimal (starts with 0x or -0x)\n" |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 44 | |
Paul Bakker | 8fe40dc | 2013-02-02 12:43:08 +0100 | [diff] [blame] | 45 | #if !defined(POLARSSL_ERROR_C) && !defined(POLARSSL_ERROR_STRERROR_DUMMY) |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 46 | int main( int argc, char *argv[] ) |
| 47 | { |
| 48 | ((void) argc); |
| 49 | ((void) argv); |
| 50 | |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 51 | polarssl_printf("POLARSSL_ERROR_C and/or POLARSSL_ERROR_STRERROR_DUMMY not defined.\n"); |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 52 | return( 0 ); |
| 53 | } |
| 54 | #else |
| 55 | int main( int argc, char *argv[] ) |
| 56 | { |
Paul Bakker | 62534dd | 2013-06-30 12:45:07 +0200 | [diff] [blame] | 57 | long int val; |
| 58 | char *end = argv[1]; |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 59 | |
| 60 | if( argc != 2 ) |
| 61 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 62 | polarssl_printf( USAGE ); |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 63 | return( 0 ); |
| 64 | } |
| 65 | |
Paul Bakker | 62534dd | 2013-06-30 12:45:07 +0200 | [diff] [blame] | 66 | val = strtol( argv[1], &end, 10 ); |
| 67 | if( *end != '\0' ) |
| 68 | { |
| 69 | val = strtol( argv[1], &end, 16 ); |
| 70 | if( *end != '\0' ) |
| 71 | { |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 72 | polarssl_printf( USAGE ); |
Paul Bakker | 62534dd | 2013-06-30 12:45:07 +0200 | [diff] [blame] | 73 | return( 0 ); |
| 74 | } |
| 75 | } |
| 76 | if( val > 0 ) |
| 77 | val = -val; |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 78 | |
Paul Bakker | 62534dd | 2013-06-30 12:45:07 +0200 | [diff] [blame] | 79 | if( val != 0 ) |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 80 | { |
| 81 | char error_buf[200]; |
Paul Bakker | 62534dd | 2013-06-30 12:45:07 +0200 | [diff] [blame] | 82 | polarssl_strerror( val, error_buf, 200 ); |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 83 | polarssl_printf("Last error was: -0x%04x - %s\n\n", (int) -val, error_buf ); |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | #if defined(_WIN32) |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 87 | polarssl_printf( " + Press Enter to exit this program.\n" ); |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 88 | fflush( stdout ); getchar(); |
| 89 | #endif |
| 90 | |
Paul Bakker | 62534dd | 2013-06-30 12:45:07 +0200 | [diff] [blame] | 91 | return( val ); |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 92 | } |
| 93 | #endif /* POLARSSL_ERROR_C */ |