cc.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * @file cc.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the author nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #ifndef LWIP_CUSTOM_CC_H
  30. #define LWIP_CUSTOM_CC_H
  31. #include <stdlib.h>
  32. #include <stdio.h>
  33. #include <errno.h>
  34. #include <stdint.h>
  35. #include <misc/debug.h>
  36. #include <misc/byteorder.h>
  37. #include <misc/packed.h>
  38. #include <misc/print_macros.h>
  39. #include <misc/byteorder.h>
  40. #include <base/BLog.h>
  41. #define u8_t uint8_t
  42. #define s8_t int8_t
  43. #define u16_t uint16_t
  44. #define s16_t int16_t
  45. #define u32_t uint32_t
  46. #define s32_t int32_t
  47. #define mem_ptr_t uintptr_t
  48. #define PACK_STRUCT_BEGIN B_START_PACKED
  49. #define PACK_STRUCT_END B_END_PACKED
  50. #define PACK_STRUCT_STRUCT B_PACKED
  51. #define LWIP_PLATFORM_DIAG(x) { if (BLog_WouldLog(BLOG_CHANNEL_lwip, BLOG_INFO)) { BLog_Append x; BLog_Finish(BLOG_CHANNEL_lwip, BLOG_INFO); } }
  52. #define LWIP_PLATFORM_ASSERT(x) { fprintf(stderr, "%s: lwip assertion failure: %s\n", __FUNCTION__, (x)); abort(); }
  53. #define U16_F PRIu16
  54. #define S16_F PRId16
  55. #define X16_F PRIx16
  56. #define U32_F PRIu32
  57. #define S32_F PRId32
  58. #define X32_F PRIx32
  59. #define SZT_F "zu"
  60. #define LWIP_PLATFORM_BYTESWAP 1
  61. #define LWIP_PLATFORM_HTONS(x) hton16(x)
  62. #define LWIP_PLATFORM_HTONL(x) hton32(x)
  63. // for BYTE_ORDER
  64. #if defined(BADVPN_USE_WINAPI) && !defined(_MSC_VER)
  65. #include <sys/param.h>
  66. #elif defined(BADVPN_LINUX)
  67. #include <endian.h>
  68. #elif defined(BADVPN_FREEBSD)
  69. #include <machine/endian.h>
  70. #else
  71. #define LITTLE_ENDIAN 1234
  72. #define BIG_ENDIAN 4321
  73. #if defined(BADVPN_LITTLE_ENDIAN)
  74. #define BYTE_ORDER LITTLE_ENDIAN
  75. #else
  76. #define BYTE_ORDER BIG_ENDIAN
  77. #endif
  78. #endif
  79. #endif