platform.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. Copyright 2006, Bernhard Fischer
  4. Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  5. */
  6. #ifndef __PLATFORM_H
  7. #define __PLATFORM_H 1
  8. /* Convenience macros to test the version of gcc. */
  9. #undef __GNUC_PREREQ
  10. #if defined __GNUC__ && defined __GNUC_MINOR__
  11. # define __GNUC_PREREQ(maj, min) \
  12. ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
  13. #else
  14. # define __GNUC_PREREQ(maj, min) 0
  15. #endif
  16. /* __restrict is known in EGCS 1.2 and above. */
  17. #if !__GNUC_PREREQ (2,92)
  18. # ifndef __restrict
  19. # define __restrict /* Ignore */
  20. # endif
  21. #endif
  22. /* Define macros for some gcc attributes. This permits us to use the
  23. macros freely, and know that they will come into play for the
  24. version of gcc in which they are supported. */
  25. #if !__GNUC_PREREQ (2,7)
  26. # ifndef __attribute__
  27. # define __attribute__(x)
  28. # endif
  29. #endif
  30. #undef inline
  31. #if defined(__STDC_VERSION__) && __STDC_VERSION__ > 199901L
  32. /* it's a keyword */
  33. #else
  34. # if __GNUC_PREREQ (2,7)
  35. # define inline __inline__
  36. # else
  37. # define inline
  38. # endif
  39. #endif
  40. #ifndef __const
  41. # define __const const
  42. #endif
  43. # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
  44. # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
  45. # define ATTRIBUTE_PACKED __attribute__ ((__packed__))
  46. # define ATTRIBUTE_ALIGNED(m) __attribute__ ((__aligned__(m)))
  47. # if __GNUC_PREREQ (3,0)
  48. # define ATTRIBUTE_ALWAYS_INLINE __attribute__ ((always_inline)) inline
  49. # else
  50. # define ATTRIBUTE_ALWAYS_INLINE inline
  51. # endif
  52. /* -fwhole-program makes all symbols local. The attribute externally_visible
  53. forces a symbol global. */
  54. # if __GNUC_PREREQ (4,1)
  55. # define ATTRIBUTE_EXTERNALLY_VISIBLE __attribute__ ((__externally_visible__))
  56. # else
  57. # define ATTRIBUTE_EXTERNALLY_VISIBLE
  58. # endif /* GNUC >= 4.1 */
  59. /* We use __extension__ in some places to suppress -pedantic warnings
  60. about GCC extensions. This feature didn't work properly before
  61. gcc 2.8. */
  62. #if !__GNUC_PREREQ (2,8)
  63. # ifndef __extension__
  64. # define __extension__
  65. # endif
  66. #endif
  67. /* gcc-2.95 had no va_copy but only __va_copy. */
  68. #if !__GNUC_PREREQ (3,0)
  69. # include <stdarg.h>
  70. # if !defined va_copy && defined __va_copy
  71. # define va_copy(d,s) __va_copy((d),(s))
  72. # endif
  73. #endif
  74. /* ---- Endian Detection ------------------------------------ */
  75. #if (defined __digital__ && defined __unix__)
  76. # include <sex.h>
  77. # define __BIG_ENDIAN__ (BYTE_ORDER == BIG_ENDIAN)
  78. # define __BYTE_ORDER BYTE_ORDER
  79. #elif !defined __APPLE__
  80. # include <byteswap.h>
  81. # include <endian.h>
  82. #endif
  83. #ifdef __BIG_ENDIAN__
  84. # define BB_BIG_ENDIAN 1
  85. # define BB_LITTLE_ENDIAN 0
  86. #elif __BYTE_ORDER == __BIG_ENDIAN
  87. # define BB_BIG_ENDIAN 1
  88. # define BB_LITTLE_ENDIAN 0
  89. #else
  90. # define BB_BIG_ENDIAN 0
  91. # define BB_LITTLE_ENDIAN 1
  92. #endif
  93. #if BB_BIG_ENDIAN
  94. #define SWAP_BE16(x) (x)
  95. #define SWAP_BE32(x) (x)
  96. #define SWAP_BE64(x) (x)
  97. #define SWAP_LE16(x) bswap_16(x)
  98. #define SWAP_LE32(x) bswap_32(x)
  99. #define SWAP_LE64(x) bswap_64(x)
  100. #else
  101. #define SWAP_BE16(x) bswap_16(x)
  102. #define SWAP_BE32(x) bswap_32(x)
  103. #define SWAP_BE64(x) bswap_64(x)
  104. #define SWAP_LE16(x) (x)
  105. #define SWAP_LE32(x) (x)
  106. #define SWAP_LE64(x) (x)
  107. #endif
  108. /* ---- Networking ------------------------------------------ */
  109. #ifndef __APPLE__
  110. # include <arpa/inet.h>
  111. #else
  112. # include <netinet/in.h>
  113. #endif
  114. #ifndef __socklen_t_defined
  115. typedef int socklen_t;
  116. #endif
  117. /* ---- Compiler dependent settings ------------------------- */
  118. #ifndef __GNUC__
  119. #if defined __INTEL_COMPILER
  120. __extension__ typedef __signed__ long long __s64;
  121. __extension__ typedef unsigned long long __u64;
  122. #endif /* __INTEL_COMPILER */
  123. #endif /* ifndef __GNUC__ */
  124. #if (defined __digital__ && defined __unix__)
  125. # undef HAVE_MNTENT_H
  126. #else
  127. # define HAVE_MNTENT_H 1
  128. #endif /* ___digital__ && __unix__ */
  129. /*----- Kernel versioning ------------------------------------*/
  130. #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
  131. /* ---- miscellaneous --------------------------------------- */
  132. #if defined(__GNU_LIBRARY__) && __GNU_LIBRARY__ < 5 && \
  133. !defined(__dietlibc__) && \
  134. !defined(_NEWLIB_VERSION) && \
  135. !(defined __digital__ && defined __unix__)
  136. # error "Sorry, this libc version is not supported :("
  137. #endif
  138. // Don't perpetuate e2fsck crap into the headers. Clean up e2fsck instead.
  139. #if defined __GLIBC__ || defined __UCLIBC__ \
  140. || defined __dietlibc__ || defined _NEWLIB_VERSION
  141. #include <features.h>
  142. #define HAVE_FEATURES_H
  143. #include <stdint.h>
  144. #define HAVE_STDINT_H
  145. #else
  146. /* Largest integral types. */
  147. #if __BIG_ENDIAN__
  148. typedef long int intmax_t;
  149. typedef unsigned long int uintmax_t;
  150. #else
  151. __extension__
  152. typedef long long int intmax_t;
  153. __extension__
  154. typedef unsigned long long int uintmax_t;
  155. #endif
  156. #endif
  157. /* uclibc does not implement daemon() for no-mmu systems.
  158. * For 0.9.29 and svn, __ARCH_USE_MMU__ indicates no-mmu reliably.
  159. * For earlier versions there is no reliable way to check if we are building
  160. * for a mmu-less system; the user should pass EXTRA_CFLAGS="-DBB_NOMMU"
  161. * on his own.
  162. */
  163. #if defined __UCLIBC__ && __UCLIBC_MAJOR__ >= 0 && __UCLIBC_MINOR__ >= 9 && \
  164. __UCLIBC_SUBLEVEL__ > 28 && !defined __ARCH_USE_MMU__
  165. #define BB_NOMMU
  166. #endif
  167. /* Platforms that haven't got dprintf need to implement fdprintf() in
  168. * libbb. This would require a platform.c. It's not going to be cleaned
  169. * out of the tree, so stop saying it should be. */
  170. #define fdprintf dprintf
  171. /* Don't use lchown with glibc older then 2.1.x ... uC-libc lacks it */
  172. #if (defined __GLIBC__ && __GLIBC__ <= 2 && __GLIBC_MINOR__ < 1) || \
  173. defined __UC_LIBC__
  174. # define lchown chown
  175. #endif
  176. /* THIS SHOULD BE CLEANED OUT OF THE TREE ENTIRELY */
  177. /* FIXME: fix tar.c! */
  178. #ifndef FNM_LEADING_DIR
  179. #define FNM_LEADING_DIR 0
  180. #endif
  181. #if (defined __digital__ && defined __unix__)
  182. #include <standards.h>
  183. #define HAVE_STANDARDS_H
  184. #include <inttypes.h>
  185. #define HAVE_INTTYPES_H
  186. #define PRIu32 "u"
  187. /* use legacy setpgrp(pidt_,pid_t) for now. move to platform.c */
  188. #define bb_setpgrp do{pid_t __me = getpid();setpgrp(__me,__me);}while(0)
  189. #if !defined ADJ_OFFSET_SINGLESHOT && defined MOD_CLKA && defined MOD_OFFSET
  190. #define ADJ_OFFSET_SINGLESHOT (MOD_CLKA | MOD_OFFSET)
  191. #endif
  192. #if !defined ADJ_FREQUENCY && defined MOD_FREQUENCY
  193. #define ADJ_FREQUENCY MOD_FREQUENCY
  194. #endif
  195. #if !defined ADJ_TIMECONST && defined MOD_TIMECONST
  196. #define ADJ_TIMECONST MOD_TIMECONST
  197. #endif
  198. #if !defined ADJ_TICK && defined MOD_CLKB
  199. #define ADJ_TICK MOD_CLKB
  200. #endif
  201. #else
  202. #define bb_setpgrp setpgrp()
  203. #endif
  204. #if defined(__linux__)
  205. #include <sys/mount.h>
  206. // Make sure we have all the new mount flags we actually try to use.
  207. #ifndef MS_BIND
  208. #define MS_BIND (1<<12)
  209. #endif
  210. #ifndef MS_MOVE
  211. #define MS_MOVE (1<<13)
  212. #endif
  213. #ifndef MS_RECURSIVE
  214. #define MS_RECURSIVE (1<<14)
  215. #endif
  216. #ifndef MS_SILENT
  217. #define MS_SILENT (1<<15)
  218. #endif
  219. // The shared subtree stuff, which went in around 2.6.15
  220. #ifndef MS_UNBINDABLE
  221. #define MS_UNBINDABLE (1<<17)
  222. #endif
  223. #ifndef MS_PRIVATE
  224. #define MS_PRIVATE (1<<18)
  225. #endif
  226. #ifndef MS_SLAVE
  227. #define MS_SLAVE (1<<19)
  228. #endif
  229. #ifndef MS_SHARED
  230. #define MS_SHARED (1<<20)
  231. #endif
  232. #if !defined(BLKSSZGET)
  233. #define BLKSSZGET _IO(0x12, 104)
  234. #endif
  235. #if !defined(BLKGETSIZE64)
  236. #define BLKGETSIZE64 _IOR(0x12,114,size_t)
  237. #endif
  238. #endif
  239. #endif /* platform.h */