You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

error_private.h 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under both the BSD-style license (found in the
  6. * LICENSE file in the root directory of this source tree) and the GPLv2 (found
  7. * in the COPYING file in the root directory of this source tree).
  8. * You may select, at your option, one of the above-listed licenses.
  9. */
  10. /* Note : this module is expected to remain private, do not expose it */
  11. #ifndef ERROR_H_MODULE
  12. #define ERROR_H_MODULE
  13. #if defined (__cplusplus)
  14. extern "C" {
  15. #endif
  16. /* ****************************************
  17. * Dependencies
  18. ******************************************/
  19. #include <stddef.h> /* size_t */
  20. #include "zstd_errors.h" /* enum list */
  21. /* ****************************************
  22. * Compiler-specific
  23. ******************************************/
  24. #if defined(__GNUC__)
  25. # define ERR_STATIC static __attribute__((unused))
  26. #elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
  27. # define ERR_STATIC static inline
  28. #elif defined(_MSC_VER)
  29. # define ERR_STATIC static __inline
  30. #else
  31. # define ERR_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
  32. #endif
  33. /*-****************************************
  34. * Customization (error_public.h)
  35. ******************************************/
  36. typedef ZSTD_ErrorCode ERR_enum;
  37. #define PREFIX(name) ZSTD_error_##name
  38. /*-****************************************
  39. * Error codes handling
  40. ******************************************/
  41. #undef ERROR /* reported already defined on VS 2015 (Rich Geldreich) */
  42. #define ERROR(name) ZSTD_ERROR(name)
  43. #define ZSTD_ERROR(name) ((size_t)-PREFIX(name))
  44. ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
  45. ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); }
  46. /*-****************************************
  47. * Error Strings
  48. ******************************************/
  49. const char* ERR_getErrorString(ERR_enum code); /* error_private.c */
  50. ERR_STATIC const char* ERR_getErrorName(size_t code)
  51. {
  52. return ERR_getErrorString(ERR_getErrorCode(code));
  53. }
  54. #if defined (__cplusplus)
  55. }
  56. #endif
  57. #endif /* ERROR_H_MODULE */