PageRenderTime 33ms CodeModel.GetById 7ms RepoModel.GetById 1ms app.codeStats 0ms

/programs/util/strerror.c

https://github.com/leg0/polarssl
C | 79 lines | 43 code | 12 blank | 24 comment | 6 complexity | 988b89e42d64e33402de6b59630f6dec MD5 | raw file
Possible License(s): GPL-2.0
  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. #ifndef _CRT_SECURE_NO_DEPRECATE
  26. #define _CRT_SECURE_NO_DEPRECATE 1
  27. #endif
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include <stdio.h>
  31. #include "polarssl/config.h"
  32. #include "polarssl/error.h"
  33. #define USAGE \
  34. "\n usage: strerror <errorcode>\n"
  35. #if !defined(POLARSSL_ERROR_C) && !defined(POLARSSL_ERROR_STRERROR_DUMMY)
  36. int main( int argc, char *argv[] )
  37. {
  38. ((void) argc);
  39. ((void) argv);
  40. printf("POLARSSL_ERROR_C and/or POLARSSL_ERROR_STRERRO_DUMMY not defined.\n");
  41. return( 0 );
  42. }
  43. #else
  44. int main( int argc, char *argv[] )
  45. {
  46. int ret;
  47. if( argc != 2 )
  48. {
  49. printf( USAGE );
  50. return( 0 );
  51. }
  52. ret = atoi( argv[1] );
  53. if( ret > 0 )
  54. ret = - ret;
  55. if( ret != 0 )
  56. {
  57. char error_buf[200];
  58. error_strerror( ret, error_buf, 200 );
  59. printf("Last error was: %d - %s\n\n", ret, error_buf );
  60. }
  61. #if defined(_WIN32)
  62. printf( " + Press Enter to exit this program.\n" );
  63. fflush( stdout ); getchar();
  64. #endif
  65. return( ret );
  66. }
  67. #endif /* POLARSSL_ERROR_C */