| 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 | |
| 29 | #include "udis86_types.h" |
| 30 | |
| 31 | #ifdef HAVE_CONFIG_H |
| 32 | # include <config.h> |
| 33 | #endif /* HAVE_CONFIG_H */ |
| 34 | |
| 35 | #if defined(UD_DEBUG) && HAVE_ASSERT_H |
| 36 | # define UD_ASSERT(_x) ASSERT(_x) |
| 37 | #else |
| 38 | # define UD_ASSERT(_x) |
| 39 | #endif /* !HAVE_ASSERT_H */ |
| 40 | |
| 41 | #if defined(UD_DEBUG) |
| 42 | #define UDERR(u, msg) \ |
| 43 | do { \ |
| 44 | (u)->error = 1; \ |
| 45 | fprintf(stderr, "decode-error: %s:%d: %s", \ |
| 46 | __FILE__, __LINE__, (msg)); \ |
| 47 | } while (0) |
| 48 | #else |
| 49 | #define UDERR(u, m) \ |
| 50 | do { \ |
| 51 | (u)->error = 1; \ |
| 52 | } while (0) |
| 53 | #endif /* !LOGERR */ |
| 54 | |
| 55 | #define UD_RETURN_ON_ERROR(u) \ |
| 56 | do { \ |
| 57 | if ((u)->error != 0) { \ |
| 58 | return (u)->error; \ |
| 59 | } \ |
| 60 | } while (0) |
| 61 | |
| 62 | #define UD_RETURN_WITH_ERROR(u, m) \ |
| 63 | do { \ |
| 64 | UDERR(u, m); \ |
| 65 | return (u)->error; \ |
| 66 | } while (0) |
| 67 | |
| 68 | #ifndef __UD_STANDALONE__ |
| 69 | # define UD_NON_STANDALONE(x) x |
| 70 | #else |
| 71 | # define UD_NON_STANDALONE(x) |
| 72 | #endif |
| 73 | |
| 74 | /* printf formatting int64 specifier */ |
| 75 | #ifdef FMT64 |
| 76 | # undef FMT64 |
| 77 | #endif |
| 78 | #if defined(_MSC_VER) || defined(__BORLANDC__) |
| 79 | # define FMT64 "I64" |
| 80 | #else |
| 81 | # if defined(__APPLE__) |
| 82 | # define FMT64 "ll" |
| 83 | # elif defined(__amd64__) || defined(__x86_64__) |
| 84 | # define FMT64 "l" |
| 85 | # else |
| 86 | # define FMT64 "ll" |
| 87 | # endif /* !x64 */ |
| 88 | #endif |
| 89 | |
| 90 | /* define an inline macro */ |
| 91 | #if defined(_MSC_VER) || defined(__BORLANDC__) |
| 92 | # define UD_INLINE __inline /* MS Visual Studio requires __inline |
| 93 | instead of inline for C code */ |
| 94 | #else |
| 95 | # define UD_INLINE inline |
| 96 | #endif |
| 97 | |
| 98 | #endif /* _UDINT_H_ */ |
| 99 | |