3
0

platform.h 16 KB

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