X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=include%2Fplatform.h;h=2b57cd5a2b1f623d5970bad76874cff5879756ec;hb=80c5b6893d4708b3683ad9a51c990a326a8f1dff;hp=1cc588690554a20a3c2817e136e983fbd640aa2a;hpb=95b83ba4f81f0985e2aeb9aec9cd67db7d5d1126;p=oweals%2Fbusybox.git diff --git a/include/platform.h b/include/platform.h index 1cc588690..2b57cd5a2 100644 --- a/include/platform.h +++ b/include/platform.h @@ -1,19 +1,24 @@ /* vi: set sw=4 ts=4: */ /* - Copyright 2006, Bernhard Reutner-Fischer - - Licensed under the GPL v2 or later, see the file LICENSE in this tarball. -*/ -#ifndef BB_PLATFORM_H + * Copyright 2006, Bernhard Reutner-Fischer + * + * Licensed under GPLv2 or later, see file LICENSE in this source tree. + */ +#ifndef BB_PLATFORM_H #define BB_PLATFORM_H 1 /* Assume all these functions exist by default. Platforms where it is not * true will #undef them below. */ -#define HAVE_FDPRINTF 1 +#define HAVE_CLEARENV 1 +#define HAVE_FDATASYNC 1 +#define HAVE_DPRINTF 1 #define HAVE_MEMRCHR 1 #define HAVE_MKDTEMP 1 +#define HAVE_PTSNAME_R 1 #define HAVE_SETBIT 1 +#define HAVE_SIGHANDLER_T 1 +#define HAVE_STPCPY 1 #define HAVE_STRCASESTR 1 #define HAVE_STRCHRNUL 1 #define HAVE_STRSEP 1 @@ -150,41 +155,50 @@ /* ---- Endian Detection ------------------------------------ */ +#include #if defined(__digital__) && defined(__unix__) # include -# define __BIG_ENDIAN__ (BYTE_ORDER == BIG_ENDIAN) -# define __BYTE_ORDER BYTE_ORDER -#elif defined __FreeBSD__ -# include /* rlimit */ +#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \ + || defined(__APPLE__) +# include /* rlimit */ # include # define bswap_64 __bswap64 # define bswap_32 __bswap32 # define bswap_16 __bswap16 -# define __BIG_ENDIAN__ (_BYTE_ORDER == _BIG_ENDIAN) -#elif !defined __APPLE__ && !defined __OpenBSD__ +#else # include # include #endif -#if defined(__BIG_ENDIAN__) && __BIG_ENDIAN__ +#if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN # define BB_BIG_ENDIAN 1 # define BB_LITTLE_ENDIAN 0 -#elif defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN +#elif defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN +# define BB_BIG_ENDIAN 0 +# define BB_LITTLE_ENDIAN 1 +#elif defined(_BYTE_ORDER) && _BYTE_ORDER == _BIG_ENDIAN # define BB_BIG_ENDIAN 1 # define BB_LITTLE_ENDIAN 0 -#elif defined(_BYTE_ORDER) && _BYTE_ORDER == _BIG_ENDIAN +#elif defined(_BYTE_ORDER) && _BYTE_ORDER == _LITTLE_ENDIAN +# define BB_BIG_ENDIAN 0 +# define BB_LITTLE_ENDIAN 1 +#elif defined(BYTE_ORDER) && BYTE_ORDER == BIG_ENDIAN # define BB_BIG_ENDIAN 1 # define BB_LITTLE_ENDIAN 0 -#elif (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN) || defined(__386__) +#elif defined(BYTE_ORDER) && BYTE_ORDER == LITTLE_ENDIAN # define BB_BIG_ENDIAN 0 # define BB_LITTLE_ENDIAN 1 -#elif defined(_BYTE_ORDER) && _BYTE_ORDER == _LITTLE_ENDIAN +#elif defined(__386__) # define BB_BIG_ENDIAN 0 # define BB_LITTLE_ENDIAN 1 #else # error "Can't determine endianness" #endif +#if ULONG_MAX > 0xffffffff +# define bb_bswap_64(x) bswap_64(x) +#endif + /* SWAP_LEnn means "convert CPU<->little_endian by swapping bytes" */ #if BB_BIG_ENDIAN # define SWAP_BE16(x) (x) @@ -192,26 +206,31 @@ # define SWAP_BE64(x) (x) # define SWAP_LE16(x) bswap_16(x) # define SWAP_LE32(x) bswap_32(x) -# define SWAP_LE64(x) bswap_64(x) +# define SWAP_LE64(x) bb_bswap_64(x) +# define IF_BIG_ENDIAN(...) __VA_ARGS__ +# define IF_LITTLE_ENDIAN(...) #else # define SWAP_BE16(x) bswap_16(x) # define SWAP_BE32(x) bswap_32(x) -# define SWAP_BE64(x) bswap_64(x) +# define SWAP_BE64(x) bb_bswap_64(x) # define SWAP_LE16(x) (x) # define SWAP_LE32(x) (x) # define SWAP_LE64(x) (x) +# define IF_BIG_ENDIAN(...) +# define IF_LITTLE_ENDIAN(...) __VA_ARGS__ #endif /* ---- Unaligned access ------------------------------------ */ +#include +typedef int bb__aliased_int FIX_ALIASING; +typedef uint16_t bb__aliased_uint16_t FIX_ALIASING; +typedef uint32_t bb__aliased_uint32_t FIX_ALIASING; + /* NB: unaligned parameter should be a pointer, aligned one - * a lvalue. This makes it more likely to not swap them by mistake */ #if defined(i386) || defined(__x86_64__) || defined(__powerpc__) -# include -typedef int bb__aliased_int FIX_ALIASING; -typedef uint16_t bb__aliased_uint16_t FIX_ALIASING; -typedef uint32_t bb__aliased_uint32_t FIX_ALIASING; # define move_from_unaligned_int(v, intp) ((v) = *(bb__aliased_int*)(intp)) # define move_from_unaligned16(v, u16p) ((v) = *(bb__aliased_uint16_t*)(u16p)) # define move_from_unaligned32(v, u32p) ((v) = *(bb__aliased_uint32_t*)(u32p)) @@ -236,12 +255,20 @@ typedef uint32_t bb__aliased_uint32_t FIX_ALIASING; /* ---- Compiler dependent settings ------------------------- */ #if (defined __digital__ && defined __unix__) \ - || defined __APPLE__ || defined __FreeBSD__ || defined __OpenBSD__ + || defined __APPLE__ \ + || defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__ +# undef HAVE_CLEARENV +# undef HAVE_FDATASYNC # undef HAVE_MNTENT_H +# undef HAVE_PTSNAME_R # undef HAVE_SYS_STATFS_H +# undef HAVE_SIGHANDLER_T +# undef HAVE_XTABS +# undef HAVE_DPRINTF #else # define HAVE_MNTENT_H 1 # define HAVE_SYS_STATFS_H 1 +# define HAVE_XTABS 1 #endif /*----- Kernel versioning ------------------------------------*/ @@ -250,15 +277,6 @@ typedef uint32_t bb__aliased_uint32_t FIX_ALIASING; /* ---- Miscellaneous --------------------------------------- */ -#if defined(__GNU_LIBRARY__) && __GNU_LIBRARY__ < 5 && \ - !defined(__dietlibc__) && \ - !defined(_NEWLIB_VERSION) && \ - !(defined __digital__ && defined __unix__) -# error "Sorry, this libc version is not supported :(" -#endif - -/* Don't perpetuate e2fsck crap into the headers. Clean up e2fsck instead. */ - #if defined __GLIBC__ || defined __UCLIBC__ \ || defined __dietlibc__ || defined _NEWLIB_VERSION # include @@ -314,11 +332,6 @@ typedef unsigned smalluint; # define USE_FOR_MMU(...) __VA_ARGS__ #endif -/* Don't use lchown with glibc older than 2.1.x */ -#if defined(__GLIBC__) && __GLIBC__ <= 2 && __GLIBC_MINOR__ < 1 -# define lchown chown -#endif - #if defined(__digital__) && defined(__unix__) # include @@ -339,25 +352,27 @@ typedef unsigned smalluint; # define ADJ_TICK MOD_CLKB # endif +# undef HAVE_STPCPY + #else # define bb_setpgrp() setpgrp() #endif -#if defined(__GLIBC__) -# define fdprintf dprintf -#endif +#include +#define fdprintf dprintf #if defined(__dietlibc__) # undef HAVE_STRCHRNUL #endif #if defined(__WATCOMC__) -# undef HAVE_FDPRINTF +# undef HAVE_DPRINTF # undef HAVE_MEMRCHR # undef HAVE_MKDTEMP # undef HAVE_SETBIT +# undef HAVE_STPCPY # undef HAVE_STRCASESTR # undef HAVE_STRCHRNUL # undef HAVE_STRSEP @@ -374,8 +389,8 @@ typedef unsigned smalluint; * These must come after all the HAVE_* macros are defined (or not) */ -#ifndef HAVE_FDPRINTF -extern int fdprintf(int fd, const char *format, ...); +#ifndef HAVE_DPRINTF +extern int dprintf(int fd, const char *format, ...); #endif #ifndef HAVE_MEMRCHR @@ -391,6 +406,14 @@ extern char *mkdtemp(char *template) FAST_FUNC; # define clrbit(a, b) ((a)[(b) >> 3] &= ~(1 << ((b) & 7))) #endif +#ifndef HAVE_SIGHANDLER_T +typedef void (*sighandler_t)(int); +#endif + +#ifndef HAVE_STPCPY +extern char *stpcpy(char *p, const char *to_add) FAST_FUNC; +#endif + #ifndef HAVE_STRCASESTR extern char *strcasestr(const char *s, const char *pattern) FAST_FUNC; #endif