PageRenderTime 56ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/source/polarssl/scripts/data_files/error.fmt

https://bitbucket.org/nqminh/filagree
Oracle Forms | 123 lines | 96 code | 27 blank | 0 comment | 0 complexity | 7f970a4683b263b13b0b9f4568b5b256 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. #include "polarssl/error.h"
  28. HEADER_INCLUDED
  29. #include <string.h>
  30. #if defined _MSC_VER && !defined snprintf
  31. #define snprintf _snprintf
  32. #endif
  33. void polarssl_strerror( int ret, char *buf, size_t buflen )
  34. {
  35. size_t len;
  36. int use_ret;
  37. memset( buf, 0x00, buflen );
  38. if( ret < 0 )
  39. ret = -ret;
  40. if( ret & 0xFF80 )
  41. {
  42. use_ret = ret & 0xFF80;
  43. // High level error codes
  44. //
  45. HIGH_LEVEL_CODE_CHECKS
  46. if( strlen( buf ) == 0 )
  47. snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
  48. }
  49. use_ret = ret & ~0xFF80;
  50. if( use_ret == 0 )
  51. return;
  52. // If high level code is present, make a concatenation between both
  53. // error strings.
  54. //
  55. len = strlen( buf );
  56. if( len > 0 )
  57. {
  58. if( buflen - len < 5 )
  59. return;
  60. snprintf( buf + len, buflen - len, " : " );
  61. buf += len + 3;
  62. buflen -= len + 3;
  63. }
  64. // Low level error codes
  65. //
  66. LOW_LEVEL_CODE_CHECKS
  67. if( strlen( buf ) != 0 )
  68. return;
  69. snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
  70. }
  71. #if defined(POLARSSL_ERROR_STRERROR_BC)
  72. void error_strerror( int ret, char *buf, size_t buflen )
  73. {
  74. return polarssl_strerror( ret, buf, buflen );
  75. }
  76. #endif /* POLARSSL_ERROR_STRERROR_BC */
  77. #else /* POLARSSL_ERROR_C */
  78. #if defined(POLARSSL_ERROR_STRERROR_DUMMY)
  79. #include <string.h>
  80. /*
  81. * Provide an non-function in case POLARSSL_ERROR_C is not defined
  82. */
  83. void polarssl_strerror( int ret, char *buf, size_t buflen )
  84. {
  85. ((void) ret);
  86. if( buflen > 0 )
  87. buf[0] = '\0';
  88. }
  89. #if defined(POLARSSL_ERROR_STRERROR_BC)
  90. void error_strerror( int ret, char *buf, size_t buflen )
  91. {
  92. return polarssl_strerror( ret, buf, buflen );
  93. }
  94. #endif /* POLARSSL_ERROR_STRERROR_BC */
  95. #endif /* POLARSSL_ERROR_STRERROR_DUMMY */
  96. #endif /* POLARSSL_ERROR_C */