udint.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* udis86 - libudis86/udint.h -- definitions for internal use only
  2. *
  3. * Copyright (c) 2002-2009 Vivek Thampi
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * * Redistributions of source code must retain the above copyright notice,
  10. * this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  16. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  19. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  22. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #ifndef _UDINT_H_
  27. #define _UDINT_H_
  28. #include "types.h"
  29. #ifdef HAVE_CONFIG_H
  30. # include <config.h>
  31. #endif /* HAVE_CONFIG_H */
  32. #if defined(UD_DEBUG) && HAVE_ASSERT_H
  33. # include <assert.h>
  34. # define UD_ASSERT(_x) assert(_x)
  35. #else
  36. # define UD_ASSERT(_x)
  37. #endif /* !HAVE_ASSERT_H */
  38. #if defined(UD_DEBUG)
  39. #define UDERR(u, msg) \
  40. do { \
  41. (u)->error = 1; \
  42. fprintf(stderr, "decode-error: %s:%d: %s", \
  43. __FILE__, __LINE__, (msg)); \
  44. } while (0)
  45. #else
  46. #define UDERR(u, m) \
  47. do { \
  48. (u)->error = 1; \
  49. } while (0)
  50. #endif /* !LOGERR */
  51. #define UD_RETURN_ON_ERROR(u) \
  52. do { \
  53. if ((u)->error != 0) { \
  54. return (u)->error; \
  55. } \
  56. } while (0)
  57. #define UD_RETURN_WITH_ERROR(u, m) \
  58. do { \
  59. UDERR(u, m); \
  60. return (u)->error; \
  61. } while (0)
  62. #ifndef __UD_STANDALONE__
  63. # define UD_NON_STANDALONE(x) x
  64. #else
  65. # define UD_NON_STANDALONE(x)
  66. #endif
  67. /* printf formatting int64 specifier */
  68. #ifdef FMT64
  69. # undef FMT64
  70. #endif
  71. #if defined(_MSC_VER) || defined(__BORLANDC__)
  72. # define FMT64 "I64"
  73. #else
  74. # if defined(__APPLE__) || defined(__OpenBSD__)
  75. # define FMT64 "ll"
  76. # elif defined(__amd64__) || defined(__x86_64__)
  77. # define FMT64 "l"
  78. # else
  79. # define FMT64 "ll"
  80. # endif /* !x64 */
  81. #endif
  82. /* define an inline macro */
  83. #if defined(_MSC_VER) || defined(__BORLANDC__)
  84. # define UD_INLINE __inline /* MS Visual Studio requires __inline
  85. instead of inline for C code */
  86. #else
  87. # define UD_INLINE inline
  88. #endif
  89. #endif /* _UDINT_H_ */