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