diff options
Diffstat (limited to 'builtins/endianness')
-rwxr-xr-x | builtins/endianness | 62 |
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 |