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 | |
| 26 | #ifndef _CRT_SECURE_NO_DEPRECATE |
| 27 | #define _CRT_SECURE_NO_DEPRECATE 1 |
| 28 | #endif |
| 29 | |
| 30 | #include <stdlib.h> |
| 31 | #include <string.h> |
| 32 | #include <stdio.h> |
| 33 | |
| 34 | #include "polarssl/config.h" |
| 35 | |
| 36 | #include "polarssl/error.h" |
| 37 | |
| 38 | #define USAGE \ |
| 39 | "\n usage: strerror <errorcode>\n" |
| 40 | |
Paul Bakker | 8fe40dc | 2013-02-02 12:43:08 +0100 | [diff] [blame] | 41 | #if !defined(POLARSSL_ERROR_C) && !defined(POLARSSL_ERROR_STRERROR_DUMMY) |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 42 | int main( int argc, char *argv[] ) |
| 43 | { |
| 44 | ((void) argc); |
| 45 | ((void) argv); |
| 46 | |
Paul Bakker | 8fe40dc | 2013-02-02 12:43:08 +0100 | [diff] [blame] | 47 | 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] | 48 | return( 0 ); |
| 49 | } |
| 50 | #else |
| 51 | int main( int argc, char *argv[] ) |
| 52 | { |
| 53 | int ret; |
| 54 | |
| 55 | if( argc != 2 ) |
| 56 | { |
| 57 | printf( USAGE ); |
| 58 | return( 0 ); |
| 59 | } |
| 60 | |
| 61 | ret = atoi( argv[1] ); |
| 62 | if( ret > 0 ) |
| 63 | ret = - ret; |
| 64 | |
| 65 | if( ret != 0 ) |
| 66 | { |
| 67 | char error_buf[200]; |
Paul Bakker | 03a8a79 | 2013-06-30 12:18:08 +0200 | [diff] [blame] | 68 | polarssl_strerror( ret, error_buf, 200 ); |
Paul Bakker | 01cc394 | 2012-05-08 08:36:15 +0000 | [diff] [blame] | 69 | printf("Last error was: %d - %s\n\n", ret, error_buf ); |
| 70 | } |
| 71 | |
| 72 | #if defined(_WIN32) |
| 73 | printf( " + Press Enter to exit this program.\n" ); |
| 74 | fflush( stdout ); getchar(); |
| 75 | #endif |
| 76 | |
| 77 | return( ret ); |
| 78 | } |
| 79 | #endif /* POLARSSL_ERROR_C */ |