error_private.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* SPDX-License-Identifier: (GPL-2.0 or BSD-3-Clause-Clear) */
  2. /**
  3. * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
  4. * All rights reserved.
  5. */
  6. /* Note : this module is expected to remain private, do not expose it */
  7. #ifndef ERROR_H_MODULE
  8. #define ERROR_H_MODULE
  9. /* ****************************************
  10. * Dependencies
  11. ******************************************/
  12. #include <linux/types.h> /* size_t */
  13. #include <linux/zstd.h> /* enum list */
  14. /* ****************************************
  15. * Compiler-specific
  16. ******************************************/
  17. #define ERR_STATIC static __attribute__((unused))
  18. /*-****************************************
  19. * Customization (error_public.h)
  20. ******************************************/
  21. typedef ZSTD_ErrorCode ERR_enum;
  22. #define PREFIX(name) ZSTD_error_##name
  23. /*-****************************************
  24. * Error codes handling
  25. ******************************************/
  26. #define ERROR(name) ((size_t)-PREFIX(name))
  27. ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
  28. ERR_STATIC ERR_enum ERR_getErrorCode(size_t code)
  29. {
  30. if (!ERR_isError(code))
  31. return (ERR_enum)0;
  32. return (ERR_enum)(0 - code);
  33. }
  34. #endif /* ERROR_H_MODULE */