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.
 
 
 
 
 
 

378 lines
6.8 KiB

  1. /*
  2. * Type and type-support defintions
  3. *
  4. * Copyright (C) 2008-2019, Joachim Metz <joachim.metz@gmail.com>
  5. *
  6. * Refer to AUTHORS for acknowledgements.
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. #if !defined( _TYPES_H )
  22. #define _TYPES_H
  23. #include "common.h"
  24. #if defined( HAVE_LIMITS_H ) || defined( WINAPI )
  25. #include <limits.h>
  26. #endif
  27. /* Make sure to include inttypes.h or stdint.h before
  28. * PRI definitions are defined
  29. */
  30. #include <@PACKAGE@/types.h>
  31. #if defined( WINAPI ) && ( defined( _UNICODE ) || defined( UNICODE ) )
  32. #define HAVE_WIDE_SYSTEM_CHARACTER 1
  33. /* The system character type is wide
  34. * A system string contains either UTF-16 or UTF-32
  35. */
  36. typedef wchar_t system_character_t;
  37. typedef wint_t system_integer_t;
  38. #define PRIc_SYSTEM "lc"
  39. #define PRIs_SYSTEM "ls"
  40. #else
  41. /* The system character type is narrow
  42. * A system string contains either UTF-8 or extended ASCII with a codepage
  43. */
  44. typedef char system_character_t;
  45. typedef int system_integer_t;
  46. #define PRIc_SYSTEM "c"
  47. #define PRIs_SYSTEM "s"
  48. #endif /* defined( WINAPI ) && ( defined( _UNICODE ) || defined( UNICODE ) ) */
  49. /* Fallback for systems without PRI definitions
  50. */
  51. #if !defined( PRId8 )
  52. #define PRId8 "d"
  53. #endif
  54. #if !defined( PRId16 )
  55. #define PRId16 "d"
  56. #endif
  57. #if !defined( PRId32 )
  58. #if defined( WINAPI )
  59. #define PRId32 "I32d"
  60. #else
  61. #define PRId32 "d"
  62. #endif
  63. #endif /* !defined( PRId32 ) */
  64. #if !defined( PRId64 )
  65. #if defined( WINAPI )
  66. #define PRId64 "I64d"
  67. #elif __WORDSIZE == 64
  68. #define PRId64 "ld"
  69. #else
  70. #define PRId64 "lld"
  71. #endif
  72. #endif /* !defined( PRId64 ) */
  73. #if !defined( PRIi8 )
  74. #define PRIi8 "i"
  75. #endif
  76. #if !defined( PRIi16 )
  77. #define PRIi16 "i"
  78. #endif
  79. #if !defined( PRIi32 )
  80. #if defined( WINAPI )
  81. #define PRIi32 "I32i"
  82. #else
  83. #define PRIi32 "i"
  84. #endif
  85. #endif /* !defined( PRIi32 ) */
  86. #if !defined( PRIi64 )
  87. #if defined( WINAPI )
  88. #define PRIi64 "I64i"
  89. #elif __WORDSIZE == 64
  90. #define PRIi64 "li"
  91. #else
  92. #define PRIi64 "lli"
  93. #endif
  94. #endif /* !defined( PRIi64 ) */
  95. #if !defined( PRIu8 )
  96. #define PRIu8 "u"
  97. #endif
  98. #if !defined( PRIu16 )
  99. #define PRIu16 "u"
  100. #endif
  101. #if !defined( PRIu32 )
  102. #if defined( WINAPI )
  103. #define PRIu32 "I32u"
  104. #else
  105. #define PRIu32 "u"
  106. #endif
  107. #endif /* !defined( PRIu32 ) */
  108. #if !defined( PRIu64 )
  109. #if defined( WINAPI )
  110. #define PRIu64 "I64u"
  111. #elif __WORDSIZE == 64
  112. #define PRIu64 "lu"
  113. #else
  114. #define PRIu64 "llu"
  115. #endif
  116. #endif /* !defined( PRIu64 ) */
  117. #if !defined( PRIo8 )
  118. #define PRIo8 "o"
  119. #endif
  120. #if !defined( PRIo16 )
  121. #define PRIo16 "o"
  122. #endif
  123. #if !defined( PRIo32 )
  124. #if defined( WINAPI )
  125. #define PRIo32 "I32o"
  126. #else
  127. #define PRIo32 "o"
  128. #endif
  129. #endif /* !defined( PRIo32 ) */
  130. #if !defined( PRIo64 )
  131. #if defined( WINAPI )
  132. #define PRIo64 "I64o"
  133. #elif __WORDSIZE == 64
  134. #define PRIo64 "lo"
  135. #else
  136. #define PRIo64 "llo"
  137. #endif
  138. #endif /* !defined( PRIo64 ) */
  139. #if !defined( PRIx8 )
  140. #define PRIx8 "x"
  141. #endif
  142. #if !defined( PRIx16 )
  143. #define PRIx16 "x"
  144. #endif
  145. #if !defined( PRIx32 )
  146. #if defined( WINAPI )
  147. #define PRIx32 "I32x"
  148. #else
  149. #define PRIx32 "x"
  150. #endif
  151. #endif /* !defined( PRIx32 ) */
  152. #if !defined( PRIx64 )
  153. #if defined( WINAPI )
  154. #define PRIx64 "I64x"
  155. #elif __WORDSIZE == 64
  156. #define PRIx64 "lx"
  157. #else
  158. #define PRIx64 "llx"
  159. #endif
  160. #endif /* !defined( PRIx64 ) */
  161. /* Fallback for systems without printf %jd definition
  162. */
  163. #if defined( HAVE_PRINTF_JD )
  164. #define PRIjd "jd"
  165. #define PRIji "ji"
  166. #define PRIju "ju"
  167. #define PRIjx "jx"
  168. #elif SIZEOF_OFF_T == 8
  169. #define PRIjd PRId64
  170. #define PRIji PRIi64
  171. #define PRIju PRIu64
  172. #define PRIjx PRIx64
  173. #else
  174. #define PRIjd PRId32
  175. #define PRIji PRIi32
  176. #define PRIju PRIu32
  177. #define PRIjx PRIx32
  178. #endif /* defined( HAVE_PRINTF_JD ) */
  179. /* Fallback for systems without printf %zd definition
  180. */
  181. #if defined( HAVE_PRINTF_ZD )
  182. #define PRIzd "zd"
  183. #define PRIzi "zi"
  184. #define PRIzu "zu"
  185. #define PRIzx "zx"
  186. #elif defined( _MSC_VER )
  187. #define PRIzd "Id"
  188. #define PRIzi "Ii"
  189. #define PRIzu "Iu"
  190. #define PRIzx "Ix"
  191. #elif SIZEOF_SIZE_T == 8
  192. #define PRIzd PRId64
  193. #define PRIzi PRIi64
  194. #define PRIzu PRIu64
  195. #define PRIzx PRIx64
  196. #else
  197. #define PRIzd PRId32
  198. #define PRIzi PRIi32
  199. #define PRIzu PRIu32
  200. #define PRIzx PRIx32
  201. #endif /* defined( HAVE_PRINTF_ZD ) */
  202. /* Fallback for systems without (U)INTx_MAX definitions
  203. */
  204. /* The maximum signed 8-bit integer is 127 (0x7f)
  205. */
  206. #if !defined( INT8_MAX )
  207. #define INT8_MAX (0x7f)
  208. #endif
  209. /* The maximum unsigned 8-bit integer is 256 (0xff)
  210. */
  211. #if !defined( UINT8_MAX )
  212. #define UINT8_MAX (0xff)
  213. #endif
  214. /* The maximum signed 16-bit integer is 32767 (0x7ffff)
  215. */
  216. #if !defined( INT16_MAX )
  217. #define INT16_MAX (0x7fff)
  218. #endif
  219. /* The maximum unsigned 16-bit integer is 65535 (0xffff)
  220. */
  221. #if !defined( UINT16_MAX )
  222. #define UINT16_MAX (0xffff)
  223. #endif
  224. /* The maximum signed 32-bit integer is 2147483647 (0x7fffffff)
  225. */
  226. #if !defined( INT32_MAX )
  227. #define INT32_MAX (0x7fffffffL)
  228. #endif
  229. /* The maximum unsigned 32-bit integer is 4294967295 (0xffffffff)
  230. */
  231. #if !defined( UINT32_MAX )
  232. #define UINT32_MAX (0xffffffffUL)
  233. #endif
  234. /* The maximum signed 64-bit integer is 9223372036854775807 (0x7fffffffffffffff)
  235. */
  236. #if !defined( INT64_MAX )
  237. #if defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x0560 )
  238. #define INT64_MAX (0x7fffffffffffffffUL)
  239. #else
  240. #define INT64_MAX (0x7fffffffffffffffULL)
  241. #endif
  242. #endif /* !defined( INT64_MAX ) */
  243. /* The maximum unsigned 64-bit integer is 18446744073709551615 (0xffffffffffffffff)
  244. */
  245. #if !defined( UINT64_MAX )
  246. #if defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x0560 )
  247. #define UINT64_MAX (0xffffffffffffffffUL)
  248. #else
  249. #define UINT64_MAX (0xffffffffffffffffULL)
  250. #endif
  251. #endif /* !defined( UINT64_MAX ) */
  252. /* The maximum signed integer
  253. */
  254. #if !defined( INT_MAX )
  255. #define INT_MAX INT32_MAX
  256. #endif
  257. /* The maximum unsigned integer
  258. */
  259. #if !defined( UINT_MAX )
  260. #define UINT_MAX UINT32_MAX
  261. #endif
  262. /* The maximum signed long integer
  263. */
  264. #if !defined( LONG_MAX )
  265. #define LONG_MAX INT32_MAX
  266. #endif
  267. /* The maximum unsigned long integer
  268. */
  269. #if !defined( ULONG_MAX )
  270. #define ULONG_MAX UINT32_MAX
  271. #endif
  272. /* The maximum signed size type is platform dependent
  273. */
  274. #if !defined( SSIZE_MAX )
  275. #if defined( WINAPI )
  276. #if defined( _WIN64 )
  277. #define SSIZE_MAX INT64_MAX
  278. #else
  279. #define SSIZE_MAX INT32_MAX
  280. #endif
  281. #else
  282. #if __WORDSIZE == 64
  283. #define SSIZE_MAX INT64_MAX
  284. #else
  285. #define SSIZE_MAX INT32_MAX
  286. #endif
  287. #endif /* WINAPI */
  288. #endif /* SSIZE_MAX */
  289. #endif /* !defined( _TYPES_H ) */