Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 1 | /* |
| 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é-Gonnard | abd6e02 | 2013-09-20 13:30:43 +0200 | [diff] [blame^] | 26 | #include "polarssl/config.h" |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 27 | |
| 28 | #include <stdlib.h> |
| 29 | #include <string.h> |
| 30 | #include <stdio.h> |
| 31 | |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 32 | #include "polarssl/error.h" |
| 33 | |
| 34 | #define USAGE \ |
Paul Bakker | 62534dd | 2013-06-30 12:45:07 +0200 | [diff] [blame] | 35 | "\n usage: strerror <errorcode>\n" \ |
| 36 | "\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] | 37 | |
Paul Bakker | 8fe40dc | 2013-02-02 12:43:08 +0100 | [diff] [blame] | 38 | #if !defined(POLARSSL_ERROR_C) && !defined(POLARSSL_ERROR_STRERROR_DUMMY) |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 39 | int main( int argc, char *argv[] ) |
| 40 | { |
| 41 | ((void) argc); |
| 42 | ((void) argv); |
| 43 | |
Paul Bakker | 62534dd | 2013-06-30 12:45:07 +0200 | [diff] [blame] | 44 | 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] | 45 | return( 0 ); |
| 46 | } |
| 47 | #else |
| 48 | int main( int argc, char *argv[] ) |
| 49 | { |
Paul Bakker | 62534dd | 2013-06-30 12:45:07 +0200 | [diff] [blame] | 50 | long int val; |
| 51 | char *end = argv[1]; |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 52 | |
| 53 | if( argc != 2 ) |
| 54 | { |
| 55 | printf( USAGE ); |
| 56 | return( 0 ); |
| 57 | } |
| 58 | |
Paul Bakker | 62534dd | 2013-06-30 12:45:07 +0200 | [diff] [blame] | 59 | 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 Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 71 | |
Paul Bakker | 62534dd | 2013-06-30 12:45:07 +0200 | [diff] [blame] | 72 | if( val != 0 ) |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 73 | { |
| 74 | char error_buf[200]; |
Paul Bakker | 62534dd | 2013-06-30 12:45:07 +0200 | [diff] [blame] | 75 | polarssl_strerror( val, error_buf, 200 ); |
| 76 | 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] | 77 | } |
| 78 | |
| 79 | #if defined(_WIN32) |
| 80 | printf( " + Press Enter to exit this program.\n" ); |
| 81 | fflush( stdout ); getchar(); |
| 82 | #endif |
| 83 | |
Paul Bakker | 62534dd | 2013-06-30 12:45:07 +0200 | [diff] [blame] | 84 | return( val ); |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 85 | } |
| 86 | #endif /* POLARSSL_ERROR_C */ |