error_private.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) 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. /* ****************************************
  14. * Dependencies
  15. ******************************************/
  16. #include "zstd_deps.h" /* size_t */
  17. #include <linux/zstd_errors.h> /* enum list */
  18. /* ****************************************
  19. * Compiler-specific
  20. ******************************************/
  21. #define ERR_STATIC static __attribute__((unused))
  22. /*-****************************************
  23. * Customization (error_public.h)
  24. ******************************************/
  25. typedef ZSTD_ErrorCode ERR_enum;
  26. #define PREFIX(name) ZSTD_error_##name
  27. /*-****************************************
  28. * Error codes handling
  29. ******************************************/
  30. #undef ERROR /* already defined on Visual Studio */
  31. #define ERROR(name) ZSTD_ERROR(name)
  32. #define ZSTD_ERROR(name) ((size_t)-PREFIX(name))
  33. ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
  34. ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); }
  35. /* check and forward error code */
  36. #define CHECK_V_F(e, f) size_t const e = f; if (ERR_isError(e)) return e
  37. #define CHECK_F(f) { CHECK_V_F(_var_err__, f); }
  38. /*-****************************************
  39. * Error Strings
  40. ******************************************/
  41. const char* ERR_getErrorString(ERR_enum code); /* error_private.c */
  42. ERR_STATIC const char* ERR_getErrorName(size_t code)
  43. {
  44. return ERR_getErrorString(ERR_getErrorCode(code));
  45. }
  46. #endif /* ERROR_H_MODULE */