- be gentle to the intel compiler and make sure we have __u64 which is needed for...
[oweals/busybox.git] / include / platform.h
index fdaf5092065296c7b4122fbdc1198d37116781ae..69d031dcae377fddde7b25a0228aaf6afb095e11 100644 (file)
@@ -11,7 +11,7 @@
 #undef __GNUC_PREREQ
 #if defined __GNUC__ && defined __GNUC_MINOR__
 # define __GNUC_PREREQ(maj, min) \
-               ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
+               ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
 #else
 # define __GNUC_PREREQ(maj, min) 0
 #endif
@@ -34,7 +34,7 @@
 #endif
 
 #undef inline
-#if __STDC_VERSION__ > 199901L
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ > 199901L
 /* it's a keyword */
 #else
 # if __GNUC_PREREQ (2,7)
@@ -133,6 +133,14 @@ typedef int socklen_t;
 #endif
 
 /* ---- Compiler dependent settings ------------------------- */
+#if (defined __digital__ && defined __unix__)
+# undef HAVE_MNTENT_H
+#else
+# define HAVE_MNTENT_H 1
+#endif /* ___digital__ && __unix__ */
+
+/* linux/loop.h relies on __u64. Make sure we have that as a proper type
+ * until userspace is widely fixed.  */
 #ifndef __GNUC__
 #if defined __INTEL_COMPILER
 __extension__ typedef __signed__ long long __s64;
@@ -140,12 +148,6 @@ __extension__ typedef unsigned long long __u64;
 #endif /* __INTEL_COMPILER */
 #endif /* ifndef __GNUC__ */
 
-#if (defined __digital__ && defined __unix__)
-# undef HAVE_MNTENT_H
-#else
-# define HAVE_MNTENT_H 1
-#endif /* ___digital__ && __unix__ */
-
 /*----- Kernel versioning ------------------------------------*/
 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
 
@@ -179,6 +181,27 @@ typedef unsigned long long int  uintmax_t;
 #endif
 #endif
 
+/* Size-saving "small" ints (arch-dependent) */
+#if defined(i386) || defined(__x86_64__) || defined(__mips__) || defined(__cris__)
+/* add other arches which benefit from this... */
+typedef signed char smallint;
+typedef unsigned char smalluint;
+#else
+/* for arches where byte accesses generate larger code: */
+typedef int smallint;
+typedef unsigned smalluint;
+#endif
+
+/* ISO C Standard:  7.16  Boolean type and values  <stdbool.h> */
+#if (defined __digital__ && defined __unix__)
+/* old system without (proper) C99 support */
+#define bool smalluint
+#else
+/* modern system, so use it */
+#include <stdbool.h>
+#endif
+
+
 /* uclibc does not implement daemon() for no-mmu systems.
  * For 0.9.29 and svn, __ARCH_USE_MMU__ indicates no-mmu reliably.
  * For earlier versions there is no reliable way to check if we are building
@@ -193,9 +216,21 @@ typedef unsigned long long int  uintmax_t;
 /* Platforms that haven't got dprintf need to implement fdprintf() in
  * libbb.  This would require a platform.c.  It's not going to be cleaned
  * out of the tree, so stop saying it should be. */
+#if !defined(__dietlibc__)
+/* Needed for: glibc */
+/* Not needed for: dietlibc */
+/* Others: ?? (add as needed) */
 #define fdprintf dprintf
+#endif
 
-/* Don't use lchown with glibc older then 2.1.x ... uC-libc lacks it */
+#if defined(__dietlibc__)
+static ATTRIBUTE_ALWAYS_INLINE char* strchrnul(const char *s, char c) {
+       while (*s && *s != c) ++s;
+       return (char*)s;
+}
+#endif
+
+/* Don't use lchown with glibc older than 2.1.x ... uC-libc lacks it */
 #if (defined __GLIBC__ && __GLIBC__ <= 2 && __GLIBC_MINOR__ < 1) || \
     defined __UC_LIBC__
 # define lchown chown
@@ -215,7 +250,7 @@ typedef unsigned long long int  uintmax_t;
 #define PRIu32 "u"
 
 /* use legacy setpgrp(pidt_,pid_t) for now.  move to platform.c */
-#define bb_setpgrp do{pid_t __me = getpid();setpgrp(__me,__me);}while(0)
+#define bb_setpgrp do { pid_t __me = getpid(); setpgrp(__me,__me); } while (0)
 
 #if !defined ADJ_OFFSET_SINGLESHOT && defined MOD_CLKA && defined MOD_OFFSET
 #define ADJ_OFFSET_SINGLESHOT (MOD_CLKA | MOD_OFFSET)
@@ -264,7 +299,7 @@ typedef unsigned long long int  uintmax_t;
 #define MS_SHARED      (1<<20)
 #endif
 
+
 #if !defined(BLKSSZGET)
 #define BLKSSZGET _IO(0x12, 104)
 #endif