error_private.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of https://github.com/facebook/zstd.
  7. * An additional grant of patent rights can be found in the PATENTS file in the
  8. * same directory.
  9. *
  10. * This program is free software; you can redistribute it and/or modify it under
  11. * the terms of the GNU General Public License version 2 as published by the
  12. * Free Software Foundation. This program is dual-licensed; you may select
  13. * either version 2 of the GNU General Public License ("GPL") or BSD license
  14. * ("BSD").
  15. */
  16. /* Note : this module is expected to remain private, do not expose it */
  17. #ifndef ERROR_H_MODULE
  18. #define ERROR_H_MODULE
  19. /* ****************************************
  20. * Dependencies
  21. ******************************************/
  22. #include <linux/types.h> /* size_t */
  23. #include <linux/zstd.h> /* enum list */
  24. /* ****************************************
  25. * Compiler-specific
  26. ******************************************/
  27. #define ERR_STATIC static __attribute__((unused))
  28. /*-****************************************
  29. * Customization (error_public.h)
  30. ******************************************/
  31. typedef ZSTD_ErrorCode ERR_enum;
  32. #define PREFIX(name) ZSTD_error_##name
  33. /*-****************************************
  34. * Error codes handling
  35. ******************************************/
  36. #define ERROR(name) ((size_t)-PREFIX(name))
  37. ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
  38. ERR_STATIC ERR_enum ERR_getErrorCode(size_t code)
  39. {
  40. if (!ERR_isError(code))
  41. return (ERR_enum)0;
  42. return (ERR_enum)(0 - code);
  43. }
  44. #endif /* ERROR_H_MODULE */