error_private.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include <contrib/libs/zstd06/renames.h>
  2. /* ******************************************************************
  3. Error codes and messages
  4. Copyright (C) 2013-2016, Yann Collet
  5. BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
  6. Redistribution and use in source and binary forms, with or without
  7. modification, are permitted provided that the following conditions are
  8. met:
  9. * Redistributions of source code must retain the above copyright
  10. notice, this list of conditions and the following disclaimer.
  11. * Redistributions in binary form must reproduce the above
  12. copyright notice, this list of conditions and the following disclaimer
  13. in the documentation and/or other materials provided with the
  14. distribution.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  16. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  17. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  18. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  19. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  25. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. You can contact the author at :
  27. - Homepage : http://www.zstd.net
  28. ****************************************************************** */
  29. /* Note : this module is expected to remain private, do not expose it */
  30. #ifndef ERROR_H_MODULE
  31. #define ERROR_H_MODULE
  32. #if defined (__cplusplus)
  33. extern "C" {
  34. #endif
  35. /* ****************************************
  36. * Dependencies
  37. ******************************************/
  38. #include <stddef.h> /* size_t */
  39. #include "error_public.h" /* enum list */
  40. /* ****************************************
  41. * Compiler-specific
  42. ******************************************/
  43. #if defined(__GNUC__)
  44. # define ERR_STATIC static __attribute__((unused))
  45. #elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
  46. # define ERR_STATIC static inline
  47. #elif defined(_MSC_VER)
  48. # define ERR_STATIC static __inline
  49. #else
  50. # define ERR_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
  51. #endif
  52. /*-****************************************
  53. * Customization (error_public.h)
  54. ******************************************/
  55. typedef ZSTD_ErrorCode ERR_enum;
  56. #define PREFIX(name) ZSTD_error_##name
  57. /*-****************************************
  58. * Error codes handling
  59. ******************************************/
  60. #ifdef ERROR
  61. # undef ERROR /* reported already defined on VS 2015 (Rich Geldreich) */
  62. #endif
  63. #define ERROR(name) ((size_t)-PREFIX(name))
  64. ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
  65. ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); }
  66. /*-****************************************
  67. * Error Strings
  68. ******************************************/
  69. ERR_STATIC const char* ERR_getErrorString(ERR_enum code)
  70. {
  71. static const char* notErrorCode = "Unspecified error code";
  72. switch( code )
  73. {
  74. case PREFIX(no_error): return "No error detected";
  75. case PREFIX(GENERIC): return "Error (generic)";
  76. case PREFIX(prefix_unknown): return "Unknown frame descriptor";
  77. case PREFIX(frameParameter_unsupported): return "Unsupported frame parameter";
  78. case PREFIX(frameParameter_unsupportedBy32bits): return "Frame parameter unsupported in 32-bits mode";
  79. case PREFIX(compressionParameter_unsupported): return "Compression parameter is out of bound";
  80. case PREFIX(init_missing): return "Context should be init first";
  81. case PREFIX(memory_allocation): return "Allocation error : not enough memory";
  82. case PREFIX(stage_wrong): return "Operation not authorized at current processing stage";
  83. case PREFIX(dstSize_tooSmall): return "Destination buffer is too small";
  84. case PREFIX(srcSize_wrong): return "Src size incorrect";
  85. case PREFIX(corruption_detected): return "Corrupted block detected";
  86. case PREFIX(tableLog_tooLarge): return "tableLog requires too much memory : unsupported";
  87. case PREFIX(maxSymbolValue_tooLarge): return "Unsupported max Symbol Value : too large";
  88. case PREFIX(maxSymbolValue_tooSmall): return "Specified maxSymbolValue is too small";
  89. case PREFIX(dictionary_corrupted): return "Dictionary is corrupted";
  90. case PREFIX(maxCode):
  91. default: return notErrorCode;
  92. }
  93. }
  94. ERR_STATIC const char* ERR_getErrorName(size_t code)
  95. {
  96. return ERR_getErrorString(ERR_getErrorCode(code));
  97. }
  98. #if defined (__cplusplus)
  99. }
  100. #endif
  101. #endif /* ERROR_H_MODULE */