summaryrefslogtreecommitdiff
path: root/builtins/endianness
diff options
context:
space:
mode:
authorAndrew Shadura <andrewsh@debian.org>2014-09-14 17:41:43 +0200
committerAndrew Shadura <andrew@shadura.me>2015-07-25 14:44:57 +0200
commit02e4dec7376d8e7b563b8008b979682b82b23e11 (patch)
tree18b1263e3a507d785fbde6a8a09e6e019ff986a8 /builtins/endianness
parent99305952b2affb1672b6f44834378729c753aab4 (diff)
parent7bea690e43ee009efc9e8f6a45504496348cd3ee (diff)
Imported Debian patch 0.28.0-1
Diffstat (limited to 'builtins/endianness')
-rwxr-xr-xbuiltins/endianness62
1 files changed, 62 insertions, 0 deletions
diff --git a/builtins/endianness b/builtins/endianness
new file mode 100755
index 0000000..fb7d76e
--- /dev/null
+++ b/builtins/endianness
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+############################################################
+# Copyright (c) 2009 by Aleksey Cheusov
+#
+# See LICENSE file in the distribution.
+############################################################
+
+set -e
+
+LC_ALL=C
+export LC_ALL
+
+##################################################
+
+pathpart=endianness
+. mkc_check_common.sh
+
+trap "rm -f $tmpc $tmpo" 0
+
+CFLAGS="$CFLAGS -D_GNU_SOURCE -D_ALL_SOURCE"
+
+check_me (){
+ cat > "$tmpc" <<EOF
+$3
+
+int main (int argc, char **argv)
+{
+ #if $1 == $2
+ return 0;
+#else
+ error
+#endif
+}
+EOF
+ if $CC -o "$tmpo" -c $CFLAGS $CPPFLAGS "$tmpc" 2>/dev/null; then
+ return 0
+ else
+ return 1
+ fi
+}
+
+if check_me BYTE_ORDER LITTLE_ENDIAN '
+#include <sys/types.h>
+#include <sys/param.h>
+';
+then
+ echo little
+ exit 0
+fi
+
+if check_me BYTE_ORDER BIG_ENDIAN '
+#include <sys/types.h>
+#include <sys/param.h>
+';
+then
+ echo big
+ exit 0
+fi
+
+echo unknown
+exit 0