Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Translate error code to error string |
| 3 | * |
Paul Bakker | 530927b | 2015-02-13 14:24:10 +0100 | [diff] [blame] | 4 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 5 | * |
Manuel Pégourié-Gonnard | e12abf9 | 2015-01-28 17:13:45 +0000 | [diff] [blame] | 6 | * This file is part of mbed TLS (https://polarssl.org) |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 7 | * |
| 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 | |
| 23 | #ifndef _CRT_SECURE_NO_DEPRECATE |
| 24 | #define _CRT_SECURE_NO_DEPRECATE 1 |
| 25 | #endif |
| 26 | |
| 27 | #include <stdlib.h> |
| 28 | #include <string.h> |
| 29 | #include <stdio.h> |
| 30 | |
| 31 | #include "polarssl/config.h" |
| 32 | |
| 33 | #include "polarssl/error.h" |
| 34 | |
| 35 | #define USAGE \ |
| 36 | "\n usage: strerror <errorcode>\n" |
| 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 | 8fe40dc | 2013-02-02 12:43:08 +0100 | [diff] [blame] | 44 | printf("POLARSSL_ERROR_C and/or POLARSSL_ERROR_STRERRO_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 | { |
| 50 | int ret; |
| 51 | |
| 52 | if( argc != 2 ) |
| 53 | { |
| 54 | printf( USAGE ); |
| 55 | return( 0 ); |
| 56 | } |
| 57 | |
| 58 | ret = atoi( argv[1] ); |
| 59 | if( ret > 0 ) |
| 60 | ret = - ret; |
| 61 | |
| 62 | if( ret != 0 ) |
| 63 | { |
| 64 | char error_buf[200]; |
| 65 | error_strerror( ret, error_buf, 200 ); |
| 66 | printf("Last error was: %d - %s\n\n", ret, error_buf ); |
| 67 | } |
| 68 | |
| 69 | #if defined(_WIN32) |
| 70 | printf( " + Press Enter to exit this program.\n" ); |
| 71 | fflush( stdout ); getchar(); |
| 72 | #endif |
| 73 | |
| 74 | return( ret ); |
| 75 | } |
| 76 | #endif /* POLARSSL_ERROR_C */ |