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.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (c) 2016-2020, 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 /* already defined on Visual Studio */
  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. /* check and forward error code */
  47. #define CHECK_V_F(e, f) size_t const e = f; if (ERR_isError(e)) return e
  48. #define CHECK_F(f) { CHECK_V_F(_var_err__, f); }
  49. /*-****************************************
  50. * Error Strings
  51. ******************************************/
  52. const char* ERR_getErrorString(ERR_enum code); /* error_private.c */
  53. ERR_STATIC const char* ERR_getErrorName(size_t code)
  54. {
  55. return ERR_getErrorString(ERR_getErrorCode(code));
  56. }
  57. #if defined (__cplusplus)
  58. }
  59. #endif
  60. #endif /* ERROR_H_MODULE */