PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/scripts/data_files/error.fmt

https://github.com/arisec91/polarssl
Oracle Forms | 133 lines | 105 code | 28 blank | 0 comment | 0 complexity | 7b9984860e6bbf2c23b7ea945455be86 MD5 | raw file
Possible License(s): GPL-2.0
  1. /*
  2. * Error message information
  3. *
  4. * Copyright (C) 2006-2014, 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. #if !defined(POLARSSL_CONFIG_FILE)
  26. #include "polarssl/config.h"
  27. #else
  28. #include POLARSSL_CONFIG_FILE
  29. #endif
  30. #if defined(POLARSSL_ERROR_C)
  31. #include "polarssl/error.h"
  32. HEADER_INCLUDED
  33. #include <string.h>
  34. #if defined(_MSC_VER) && !defined snprintf && !defined(EFIX64) && \
  35. !defined(EFI32)
  36. #define snprintf _snprintf
  37. #endif
  38. void polarssl_strerror( int ret, char *buf, size_t buflen )
  39. {
  40. size_t len;
  41. int use_ret;
  42. if( buflen == 0 )
  43. return;
  44. memset( buf, 0x00, buflen );
  45. /* Reduce buflen to make sure MSVC _snprintf() ends with \0 as well */
  46. buflen -= 1;
  47. if( ret < 0 )
  48. ret = -ret;
  49. if( ret & 0xFF80 )
  50. {
  51. use_ret = ret & 0xFF80;
  52. // High level error codes
  53. //
  54. HIGH_LEVEL_CODE_CHECKS
  55. if( strlen( buf ) == 0 )
  56. snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
  57. }
  58. use_ret = ret & ~0xFF80;
  59. if( use_ret == 0 )
  60. return;
  61. // If high level code is present, make a concatenation between both
  62. // error strings.
  63. //
  64. len = strlen( buf );
  65. if( len > 0 )
  66. {
  67. if( buflen - len < 5 )
  68. return;
  69. snprintf( buf + len, buflen - len, " : " );
  70. buf += len + 3;
  71. buflen -= len + 3;
  72. }
  73. // Low level error codes
  74. //
  75. LOW_LEVEL_CODE_CHECKS
  76. if( strlen( buf ) != 0 )
  77. return;
  78. snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
  79. }
  80. #if defined(POLARSSL_ERROR_STRERROR_BC)
  81. void error_strerror( int ret, char *buf, size_t buflen )
  82. {
  83. polarssl_strerror( ret, buf, buflen );
  84. }
  85. #endif /* POLARSSL_ERROR_STRERROR_BC */
  86. #else /* POLARSSL_ERROR_C */
  87. #if defined(POLARSSL_ERROR_STRERROR_DUMMY)
  88. #include <string.h>
  89. /*
  90. * Provide an non-function in case POLARSSL_ERROR_C is not defined
  91. */
  92. void polarssl_strerror( int ret, char *buf, size_t buflen )
  93. {
  94. ((void) ret);
  95. if( buflen > 0 )
  96. buf[0] = '\0';
  97. }
  98. #if defined(POLARSSL_ERROR_STRERROR_BC)
  99. void error_strerror( int ret, char *buf, size_t buflen )
  100. {
  101. polarssl_strerror( ret, buf, buflen );
  102. }
  103. #endif /* POLARSSL_ERROR_STRERROR_BC */
  104. #endif /* POLARSSL_ERROR_STRERROR_DUMMY */
  105. #endif /* POLARSSL_ERROR_C */