platform.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Copyright 2006, Bernhard Reutner-Fischer
  4. *
  5. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  6. */
  7. #ifndef BB_PLATFORM_H
  8. #define BB_PLATFORM_H 1
  9. /* Convenience macros to test the version of gcc. */
  10. #undef __GNUC_PREREQ
  11. #if defined __GNUC__ && defined __GNUC_MINOR__
  12. # define __GNUC_PREREQ(maj, min) \
  13. ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
  14. #else
  15. # define __GNUC_PREREQ(maj, min) 0
  16. #endif
  17. /* __restrict is known in EGCS 1.2 and above. */
  18. #if !__GNUC_PREREQ(2,92)
  19. # ifndef __restrict
  20. # define __restrict
  21. # endif
  22. #endif
  23. #if !__GNUC_PREREQ(2,7)
  24. # ifndef __attribute__
  25. # define __attribute__(x)
  26. # endif
  27. #endif
  28. #undef inline
  29. #if defined(__STDC_VERSION__) && __STDC_VERSION__ > 199901L
  30. /* it's a keyword */
  31. #elif __GNUC_PREREQ(2,7)
  32. # define inline __inline__
  33. #else
  34. # define inline
  35. #endif
  36. #ifndef __const
  37. # define __const const
  38. #endif
  39. #define UNUSED_PARAM __attribute__ ((__unused__))
  40. #define NORETURN __attribute__ ((__noreturn__))
  41. #if __GNUC_PREREQ(4,5)
  42. # define bb_unreachable(altcode) __builtin_unreachable()
  43. #else
  44. # define bb_unreachable(altcode) altcode
  45. #endif
  46. /* "The malloc attribute is used to tell the compiler that a function
  47. * may be treated as if any non-NULL pointer it returns cannot alias
  48. * any other pointer valid when the function returns. This will often
  49. * improve optimization. Standard functions with this property include
  50. * malloc and calloc. realloc-like functions have this property as long
  51. * as the old pointer is never referred to (including comparing it
  52. * to the new pointer) after the function returns a non-NULL value."
  53. */
  54. #define RETURNS_MALLOC __attribute__ ((malloc))
  55. #define PACKED __attribute__ ((__packed__))
  56. #define ALIGNED(m) __attribute__ ((__aligned__(m)))
  57. /* __NO_INLINE__: some gcc's do not honor inlining! :( */
  58. #if __GNUC_PREREQ(3,0) && !defined(__NO_INLINE__)
  59. # define ALWAYS_INLINE __attribute__ ((always_inline)) inline
  60. /* I've seen a toolchain where I needed __noinline__ instead of noinline */
  61. # define NOINLINE __attribute__((__noinline__))
  62. # if !ENABLE_WERROR
  63. # define DEPRECATED __attribute__ ((__deprecated__))
  64. # define UNUSED_PARAM_RESULT __attribute__ ((warn_unused_result))
  65. # else
  66. # define DEPRECATED
  67. # define UNUSED_PARAM_RESULT
  68. # endif
  69. #else
  70. # define ALWAYS_INLINE inline
  71. # define NOINLINE
  72. # define DEPRECATED
  73. # define UNUSED_PARAM_RESULT
  74. #endif
  75. /* used by unit test machinery to run registration functions before calling main() */
  76. #define INIT_FUNC __attribute__ ((constructor))
  77. /* -fwhole-program makes all symbols local. The attribute externally_visible
  78. * forces a symbol global. */
  79. #if __GNUC_PREREQ(4,1)
  80. # define EXTERNALLY_VISIBLE __attribute__(( visibility("default") ))
  81. //__attribute__ ((__externally_visible__))
  82. #else
  83. # define EXTERNALLY_VISIBLE
  84. #endif
  85. /* At 4.4 gcc become much more anal about this, need to use "aliased" types */
  86. #if __GNUC_PREREQ(4,4)
  87. # define FIX_ALIASING __attribute__((__may_alias__))
  88. #else
  89. # define FIX_ALIASING
  90. #endif
  91. /* We use __extension__ in some places to suppress -pedantic warnings
  92. * about GCC extensions. This feature didn't work properly before
  93. * gcc 2.8. */
  94. #if !__GNUC_PREREQ(2,8)
  95. # ifndef __extension__
  96. # define __extension__
  97. # endif
  98. #endif
  99. /* FAST_FUNC is a qualifier which (possibly) makes function call faster
  100. * and/or smaller by using modified ABI. It is usually only needed
  101. * on non-static, busybox internal functions. Recent versions of gcc
  102. * optimize statics automatically. FAST_FUNC on static is required
  103. * only if you need to match a function pointer's type.
  104. * FAST_FUNC may not work well with -flto so allow user to disable this.
  105. * (-DFAST_FUNC= )
  106. */
  107. #ifndef FAST_FUNC
  108. # if __GNUC_PREREQ(3,0) && defined(i386)
  109. /* stdcall makes callee to pop arguments from stack, not caller */
  110. # define FAST_FUNC __attribute__((regparm(3),stdcall))
  111. /* #elif ... - add your favorite arch today! */
  112. # else
  113. # define FAST_FUNC
  114. # endif
  115. #endif
  116. /* Make all declarations hidden (-fvisibility flag only affects definitions) */
  117. /* (don't include system headers after this until corresponding pop!) */
  118. #if __GNUC_PREREQ(4,1) && !defined(__CYGWIN__)
  119. # define PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN _Pragma("GCC visibility push(hidden)")
  120. # define POP_SAVED_FUNCTION_VISIBILITY _Pragma("GCC visibility pop")
  121. #else
  122. # define PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
  123. # define POP_SAVED_FUNCTION_VISIBILITY
  124. #endif
  125. /* gcc-2.95 had no va_copy but only __va_copy. */
  126. #if !__GNUC_PREREQ(3,0)
  127. # include <stdarg.h>
  128. # if !defined va_copy && defined __va_copy
  129. # define va_copy(d,s) __va_copy((d),(s))
  130. # endif
  131. #endif
  132. /* ---- Endian Detection ------------------------------------ */
  133. #include <limits.h>
  134. #if defined(__digital__) && defined(__unix__)
  135. # include <sex.h>
  136. #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \
  137. || defined(__APPLE__)
  138. # include <sys/resource.h> /* rlimit */
  139. # include <machine/endian.h>
  140. # define bswap_64 __bswap64
  141. # define bswap_32 __bswap32
  142. # define bswap_16 __bswap16
  143. #else
  144. # include <byteswap.h>
  145. # include <endian.h>
  146. #endif
  147. #if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN
  148. # define BB_BIG_ENDIAN 1
  149. # define BB_LITTLE_ENDIAN 0
  150. #elif defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN
  151. # define BB_BIG_ENDIAN 0
  152. # define BB_LITTLE_ENDIAN 1
  153. #elif defined(_BYTE_ORDER) && _BYTE_ORDER == _BIG_ENDIAN
  154. # define BB_BIG_ENDIAN 1
  155. # define BB_LITTLE_ENDIAN 0
  156. #elif defined(_BYTE_ORDER) && _BYTE_ORDER == _LITTLE_ENDIAN
  157. # define BB_BIG_ENDIAN 0
  158. # define BB_LITTLE_ENDIAN 1
  159. #elif defined(BYTE_ORDER) && BYTE_ORDER == BIG_ENDIAN
  160. # define BB_BIG_ENDIAN 1
  161. # define BB_LITTLE_ENDIAN 0
  162. #elif defined(BYTE_ORDER) && BYTE_ORDER == LITTLE_ENDIAN
  163. # define BB_BIG_ENDIAN 0
  164. # define BB_LITTLE_ENDIAN 1
  165. #elif defined(__386__)
  166. # define BB_BIG_ENDIAN 0
  167. # define BB_LITTLE_ENDIAN 1
  168. #else
  169. # error "Can't determine endianness"
  170. #endif
  171. #if ULONG_MAX > 0xffffffff
  172. # define bb_bswap_64(x) bswap_64(x)
  173. #endif
  174. /* SWAP_LEnn means "convert CPU<->little_endian by swapping bytes" */
  175. #if BB_BIG_ENDIAN
  176. # define SWAP_BE16(x) (x)
  177. # define SWAP_BE32(x) (x)
  178. # define SWAP_BE64(x) (x)
  179. # define SWAP_LE16(x) bswap_16(x)
  180. # define SWAP_LE32(x) bswap_32(x)
  181. # define SWAP_LE64(x) bb_bswap_64(x)
  182. # define IF_BIG_ENDIAN(...) __VA_ARGS__
  183. # define IF_LITTLE_ENDIAN(...)
  184. #else
  185. # define SWAP_BE16(x) bswap_16(x)
  186. # define SWAP_BE32(x) bswap_32(x)
  187. # define SWAP_BE64(x) bb_bswap_64(x)
  188. # define SWAP_LE16(x) (x)
  189. # define SWAP_LE32(x) (x)
  190. # define SWAP_LE64(x) (x)
  191. # define IF_BIG_ENDIAN(...)
  192. # define IF_LITTLE_ENDIAN(...) __VA_ARGS__
  193. #endif
  194. /* ---- Unaligned access ------------------------------------ */
  195. #include <stdint.h>
  196. typedef int bb__aliased_int FIX_ALIASING;
  197. typedef long bb__aliased_long FIX_ALIASING;
  198. typedef uint16_t bb__aliased_uint16_t FIX_ALIASING;
  199. typedef uint32_t bb__aliased_uint32_t FIX_ALIASING;
  200. typedef uint64_t bb__aliased_uint64_t FIX_ALIASING;
  201. /* NB: unaligned parameter should be a pointer, aligned one -
  202. * a lvalue. This makes it more likely to not swap them by mistake
  203. */
  204. #if defined(i386) || defined(__x86_64__) || defined(__powerpc__)
  205. # define BB_UNALIGNED_MEMACCESS_OK 1
  206. # define move_from_unaligned_int(v, intp) ((v) = *(bb__aliased_int*)(intp))
  207. # define move_from_unaligned_long(v, longp) ((v) = *(bb__aliased_long*)(longp))
  208. # define move_from_unaligned16(v, u16p) ((v) = *(bb__aliased_uint16_t*)(u16p))
  209. # define move_from_unaligned32(v, u32p) ((v) = *(bb__aliased_uint32_t*)(u32p))
  210. # define move_to_unaligned16(u16p, v) (*(bb__aliased_uint16_t*)(u16p) = (v))
  211. # define move_to_unaligned32(u32p, v) (*(bb__aliased_uint32_t*)(u32p) = (v))
  212. /* #elif ... - add your favorite arch today! */
  213. #else
  214. # define BB_UNALIGNED_MEMACCESS_OK 0
  215. /* performs reasonably well (gcc usually inlines memcpy here) */
  216. # define move_from_unaligned_int(v, intp) (memcpy(&(v), (intp), sizeof(int)))
  217. # define move_from_unaligned_long(v, longp) (memcpy(&(v), (longp), sizeof(long)))
  218. # define move_from_unaligned16(v, u16p) (memcpy(&(v), (u16p), 2))
  219. # define move_from_unaligned32(v, u32p) (memcpy(&(v), (u32p), 4))
  220. # define move_to_unaligned16(u16p, v) do { \
  221. uint16_t __t = (v); \
  222. memcpy((u16p), &__t, 2); \
  223. } while (0)
  224. # define move_to_unaligned32(u32p, v) do { \
  225. uint32_t __t = (v); \
  226. memcpy((u32p), &__t, 4); \
  227. } while (0)
  228. #endif
  229. /* Unaligned, fixed-endian accessors */
  230. #define get_unaligned_le32(buf) ({ uint32_t v; move_from_unaligned32(v, buf); SWAP_LE32(v); })
  231. #define get_unaligned_be32(buf) ({ uint32_t v; move_from_unaligned32(v, buf); SWAP_BE32(v); })
  232. #define put_unaligned_le32(val, buf) move_to_unaligned32(buf, SWAP_LE32(val))
  233. #define put_unaligned_be32(val, buf) move_to_unaligned32(buf, SWAP_BE32(val))
  234. /* unxz needs an aligned fixed-endian accessor.
  235. * (however, the compiler does not realize it's aligned, the cast is still necessary)
  236. */
  237. #define get_le32(u32p) ({ uint32_t v = *(bb__aliased_uint32_t*)(u32p); SWAP_LE32(v); })
  238. /* ---- Size-saving "small" ints (arch-dependent) ----------- */
  239. #if defined(i386) || defined(__x86_64__) || defined(__mips__) || defined(__cris__)
  240. /* add other arches which benefit from this... */
  241. typedef signed char smallint;
  242. typedef unsigned char smalluint;
  243. #else
  244. /* for arches where byte accesses generate larger code: */
  245. typedef int smallint;
  246. typedef unsigned smalluint;
  247. #endif
  248. /* ISO C Standard: 7.16 Boolean type and values <stdbool.h> */
  249. #if (defined __digital__ && defined __unix__)
  250. /* old system without (proper) C99 support */
  251. # define bool smalluint
  252. #else
  253. /* modern system, so use it */
  254. # include <stdbool.h>
  255. #endif
  256. /*----- Kernel versioning ------------------------------------*/
  257. #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
  258. #ifdef __UCLIBC__
  259. # define UCLIBC_VERSION KERNEL_VERSION(__UCLIBC_MAJOR__, __UCLIBC_MINOR__, __UCLIBC_SUBLEVEL__)
  260. #else
  261. # define UCLIBC_VERSION 0
  262. #endif
  263. /* ---- Miscellaneous --------------------------------------- */
  264. #if defined __GLIBC__ \
  265. || defined __UCLIBC__ \
  266. || defined __dietlibc__ \
  267. || defined __BIONIC__ \
  268. || defined _NEWLIB_VERSION
  269. # include <features.h>
  270. #endif
  271. /* Define bb_setpgrp */
  272. #if defined(__digital__) && defined(__unix__)
  273. /* use legacy setpgrp(pid_t, pid_t) for now. move to platform.c */
  274. # define bb_setpgrp() do { pid_t __me = getpid(); setpgrp(__me, __me); } while (0)
  275. #else
  276. # define bb_setpgrp() setpgrp()
  277. #endif
  278. /* fdprintf is more readable, we used it before dprintf was standardized */
  279. #include <unistd.h>
  280. #define fdprintf dprintf
  281. /* Useful for defeating gcc's alignment of "char message[]"-like data */
  282. #if !defined(__s390__)
  283. /* on s390[x], non-word-aligned data accesses require larger code */
  284. # define ALIGN1 __attribute__((aligned(1)))
  285. # define ALIGN2 __attribute__((aligned(2)))
  286. # define ALIGN4 __attribute__((aligned(4)))
  287. #else
  288. /* Arches which MUST have 2 or 4 byte alignment for everything are here */
  289. # define ALIGN1
  290. # define ALIGN2
  291. # define ALIGN4
  292. #endif
  293. /*
  294. * For 0.9.29 and svn, __ARCH_USE_MMU__ indicates no-mmu reliably.
  295. * For earlier versions there is no reliable way to check if we are building
  296. * for a mmu-less system.
  297. */
  298. #if ENABLE_NOMMU || \
  299. (defined __UCLIBC__ && \
  300. UCLIBC_VERSION > KERNEL_VERSION(0, 9, 28) && \
  301. !defined __ARCH_USE_MMU__)
  302. # define BB_MMU 0
  303. # define USE_FOR_NOMMU(...) __VA_ARGS__
  304. # define USE_FOR_MMU(...)
  305. #else
  306. # define BB_MMU 1
  307. # define USE_FOR_NOMMU(...)
  308. # define USE_FOR_MMU(...) __VA_ARGS__
  309. #endif
  310. #if defined(__digital__) && defined(__unix__)
  311. # include <standards.h>
  312. # include <inttypes.h>
  313. # define PRIu32 "u"
  314. # if !defined ADJ_OFFSET_SINGLESHOT && defined MOD_CLKA && defined MOD_OFFSET
  315. # define ADJ_OFFSET_SINGLESHOT (MOD_CLKA | MOD_OFFSET)
  316. # endif
  317. # if !defined ADJ_FREQUENCY && defined MOD_FREQUENCY
  318. # define ADJ_FREQUENCY MOD_FREQUENCY
  319. # endif
  320. # if !defined ADJ_TIMECONST && defined MOD_TIMECONST
  321. # define ADJ_TIMECONST MOD_TIMECONST
  322. # endif
  323. # if !defined ADJ_TICK && defined MOD_CLKB
  324. # define ADJ_TICK MOD_CLKB
  325. # endif
  326. #endif
  327. #if defined(__CYGWIN__)
  328. # define MAXSYMLINKS SYMLOOP_MAX
  329. #endif
  330. #if defined(ANDROID) || defined(__ANDROID__)
  331. # define BB_ADDITIONAL_PATH ":/system/sbin:/system/bin:/system/xbin"
  332. # define SYS_ioprio_set __NR_ioprio_set
  333. # define SYS_ioprio_get __NR_ioprio_get
  334. #endif
  335. /* ---- Who misses what? ------------------------------------ */
  336. /* Assume all these functions and header files exist by default.
  337. * Platforms where it is not true will #undef them below.
  338. */
  339. #define HAVE_CLEARENV 1
  340. #define HAVE_FDATASYNC 1
  341. #define HAVE_DPRINTF 1
  342. #define HAVE_MEMRCHR 1
  343. #define HAVE_MKDTEMP 1
  344. #define HAVE_TTYNAME_R 1
  345. #define HAVE_PTSNAME_R 1
  346. #define HAVE_SETBIT 1
  347. #define HAVE_SIGHANDLER_T 1
  348. #define HAVE_STPCPY 1
  349. #define HAVE_MEMPCPY 1
  350. #define HAVE_STRCASESTR 1
  351. #define HAVE_STRCHRNUL 1
  352. #define HAVE_STRSEP 1
  353. #define HAVE_STRSIGNAL 1
  354. #define HAVE_STRVERSCMP 1
  355. #define HAVE_VASPRINTF 1
  356. #define HAVE_USLEEP 1
  357. #define HAVE_UNLOCKED_STDIO 1
  358. #define HAVE_UNLOCKED_LINE_OPS 1
  359. #define HAVE_GETLINE 1
  360. #define HAVE_XTABS 1
  361. #define HAVE_MNTENT_H 1
  362. #define HAVE_NET_ETHERNET_H 1
  363. #define HAVE_SYS_STATFS_H 1
  364. #define HAVE_PRINTF_PERCENTM 1
  365. #if defined(__UCLIBC__)
  366. # if UCLIBC_VERSION < KERNEL_VERSION(0, 9, 32)
  367. # undef HAVE_STRVERSCMP
  368. # endif
  369. # if UCLIBC_VERSION >= KERNEL_VERSION(0, 9, 30)
  370. # ifndef __UCLIBC_SUSV3_LEGACY__
  371. # undef HAVE_USLEEP
  372. # endif
  373. # endif
  374. #endif
  375. #if defined(__WATCOMC__)
  376. # undef HAVE_DPRINTF
  377. # undef HAVE_GETLINE
  378. # undef HAVE_MEMRCHR
  379. # undef HAVE_MKDTEMP
  380. # undef HAVE_SETBIT
  381. # undef HAVE_STPCPY
  382. # undef HAVE_STRCASESTR
  383. # undef HAVE_STRCHRNUL
  384. # undef HAVE_STRSEP
  385. # undef HAVE_STRSIGNAL
  386. # undef HAVE_STRVERSCMP
  387. # undef HAVE_VASPRINTF
  388. # undef HAVE_UNLOCKED_STDIO
  389. # undef HAVE_UNLOCKED_LINE_OPS
  390. # undef HAVE_NET_ETHERNET_H
  391. #endif
  392. #if defined(__CYGWIN__)
  393. # undef HAVE_CLEARENV
  394. # undef HAVE_FDPRINTF
  395. # undef HAVE_MEMRCHR
  396. # undef HAVE_PTSNAME_R
  397. # undef HAVE_STRVERSCMP
  398. # undef HAVE_UNLOCKED_LINE_OPS
  399. #endif
  400. /* These BSD-derived OSes share many similarities */
  401. #if (defined __digital__ && defined __unix__) \
  402. || defined __APPLE__ \
  403. || defined __OpenBSD__ || defined __NetBSD__
  404. # undef HAVE_CLEARENV
  405. # undef HAVE_FDATASYNC
  406. # undef HAVE_GETLINE
  407. # undef HAVE_MNTENT_H
  408. # undef HAVE_PTSNAME_R
  409. # undef HAVE_SYS_STATFS_H
  410. # undef HAVE_SIGHANDLER_T
  411. # undef HAVE_STRVERSCMP
  412. # undef HAVE_XTABS
  413. # undef HAVE_DPRINTF
  414. # undef HAVE_UNLOCKED_STDIO
  415. # undef HAVE_UNLOCKED_LINE_OPS
  416. # undef HAVE_PRINTF_PERCENTM
  417. #endif
  418. #if defined(__dietlibc__)
  419. # undef HAVE_STRCHRNUL
  420. #endif
  421. #if defined(__APPLE__)
  422. # undef HAVE_STRCHRNUL
  423. #endif
  424. #if defined(__FreeBSD__)
  425. /* users say mempcpy is not present in FreeBSD 9.x */
  426. # undef HAVE_MEMPCPY
  427. # undef HAVE_CLEARENV
  428. # undef HAVE_FDATASYNC
  429. # undef HAVE_MNTENT_H
  430. # undef HAVE_PTSNAME_R
  431. # undef HAVE_SYS_STATFS_H
  432. # undef HAVE_SIGHANDLER_T
  433. # undef HAVE_STRVERSCMP
  434. # undef HAVE_XTABS
  435. # undef HAVE_UNLOCKED_LINE_OPS
  436. # undef HAVE_PRINTF_PERCENTM
  437. # include <osreldate.h>
  438. # if __FreeBSD_version < 1000029
  439. # undef HAVE_STRCHRNUL /* FreeBSD added strchrnul() between 1000028 and 1000029 */
  440. # endif
  441. #endif
  442. #if defined(__NetBSD__)
  443. # define HAVE_GETLINE 1 /* Recent NetBSD versions have getline() */
  444. #endif
  445. #if defined(__digital__) && defined(__unix__)
  446. # undef HAVE_STPCPY
  447. #endif
  448. #if defined(ANDROID) || defined(__ANDROID__)
  449. # if __ANDROID_API__ < 8
  450. /* ANDROID < 8 has no [f]dprintf at all */
  451. # undef HAVE_DPRINTF
  452. # elif __ANDROID_API__ < 21
  453. /* ANDROID < 21 has fdprintf */
  454. # define dprintf fdprintf
  455. # else
  456. /* ANDROID >= 21 has standard dprintf */
  457. # endif
  458. # if __ANDROID_API__ < 21
  459. # undef HAVE_TTYNAME_R
  460. # undef HAVE_GETLINE
  461. # undef HAVE_STPCPY
  462. # endif
  463. # undef HAVE_MEMPCPY
  464. # undef HAVE_STRCHRNUL
  465. # undef HAVE_STRVERSCMP
  466. # undef HAVE_UNLOCKED_LINE_OPS
  467. # undef HAVE_NET_ETHERNET_H
  468. # undef HAVE_PRINTF_PERCENTM
  469. #endif
  470. /*
  471. * Now, define prototypes for all the functions defined in platform.c
  472. * These must come after all the HAVE_* macros are defined (or not)
  473. */
  474. #ifndef HAVE_DPRINTF
  475. extern int dprintf(int fd, const char *format, ...);
  476. #endif
  477. #ifndef HAVE_MEMRCHR
  478. extern void *memrchr(const void *s, int c, size_t n) FAST_FUNC;
  479. #endif
  480. #ifndef HAVE_MKDTEMP
  481. extern char *mkdtemp(char *template) FAST_FUNC;
  482. #endif
  483. #ifndef HAVE_TTYNAME_R
  484. #define ttyname_r bb_ttyname_r
  485. extern int ttyname_r(int fd, char *buf, size_t buflen);
  486. #endif
  487. #ifndef HAVE_SETBIT
  488. # define setbit(a, b) ((a)[(b) >> 3] |= 1 << ((b) & 7))
  489. # define clrbit(a, b) ((a)[(b) >> 3] &= ~(1 << ((b) & 7)))
  490. #endif
  491. #ifndef HAVE_SIGHANDLER_T
  492. typedef void (*sighandler_t)(int);
  493. #endif
  494. #ifndef HAVE_STPCPY
  495. extern char *stpcpy(char *p, const char *to_add) FAST_FUNC;
  496. #endif
  497. #ifndef HAVE_MEMPCPY
  498. #include <string.h>
  499. /* In case we are wrong about !HAVE_MEMPCPY, and toolchain _does_ have
  500. * mempcpy(), avoid colliding with it:
  501. */
  502. #define mempcpy bb__mempcpy
  503. static ALWAYS_INLINE void *mempcpy(void *dest, const void *src, size_t len)
  504. {
  505. return memcpy(dest, src, len) + len;
  506. }
  507. #endif
  508. #ifndef HAVE_STRCASESTR
  509. extern char *strcasestr(const char *s, const char *pattern) FAST_FUNC;
  510. #endif
  511. #ifndef HAVE_STRCHRNUL
  512. extern char *strchrnul(const char *s, int c) FAST_FUNC;
  513. #endif
  514. #ifndef HAVE_STRSEP
  515. extern char *strsep(char **stringp, const char *delim) FAST_FUNC;
  516. #endif
  517. #ifndef HAVE_STRSIGNAL
  518. /* Not exactly the same: instead of "Stopped" it shows "STOP" etc */
  519. # define strsignal(sig) get_signame(sig)
  520. #endif
  521. #ifndef HAVE_USLEEP
  522. extern int usleep(unsigned) FAST_FUNC;
  523. #endif
  524. #ifndef HAVE_VASPRINTF
  525. extern int vasprintf(char **string_ptr, const char *format, va_list p) FAST_FUNC;
  526. #endif
  527. #ifndef HAVE_GETLINE
  528. # include <stdio.h> /* for FILE */
  529. # include <sys/types.h> /* size_t */
  530. extern ssize_t getline(char **lineptr, size_t *n, FILE *stream) FAST_FUNC;
  531. #endif
  532. #endif