PageRenderTime 49ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/scripts/data_files/error.fmt

https://github.com/leg0/polarssl
Oracle Forms | 89 lines | 70 code | 19 blank | 0 comment | 0 complexity | bc007525b1302dce223854a7e7d5c9b1 MD5 | raw file
Possible License(s): GPL-2.0
  1. /*
  2. * Error message information
  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. #include "polarssl/config.h"
  26. #if defined(POLARSSL_ERROR_C)
  27. HEADER_INCLUDED
  28. #include <string.h>
  29. #if defined _MSC_VER && !defined snprintf
  30. #define snprintf _snprintf
  31. #endif
  32. void error_strerror( int ret, char *buf, size_t buflen )
  33. {
  34. size_t len;
  35. int use_ret;
  36. memset( buf, 0x00, buflen );
  37. if( ret < 0 )
  38. ret = -ret;
  39. if( ret & 0xFF80 )
  40. {
  41. use_ret = ret & 0xFF80;
  42. // High level error codes
  43. //
  44. HIGH_LEVEL_CODE_CHECKS
  45. if( strlen( buf ) == 0 )
  46. snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
  47. }
  48. use_ret = ret & ~0xFF80;
  49. if( use_ret == 0 )
  50. return;
  51. // If high level code is present, make a concatenation between both
  52. // error strings.
  53. //
  54. len = strlen( buf );
  55. if( len > 0 )
  56. {
  57. if( buflen - len < 5 )
  58. return;
  59. snprintf( buf + len, buflen - len, " : " );
  60. buf += len + 3;
  61. buflen -= len + 3;
  62. }
  63. // Low level error codes
  64. //
  65. LOW_LEVEL_CODE_CHECKS
  66. if( strlen( buf ) != 0 )
  67. return;
  68. snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
  69. }
  70. #endif /* POLARSSL_ERROR_C */