diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-08-28 17:33:16 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-10-12 18:20:06 +0900 |
| commit | 471479e723157c1a7df2023ab2eea24fa4ca2246 (patch) | |
| tree | 8d5c18642f44ca2f47832b66b6a49e5f0250afb7 /include | |
| parent | 397b005715b443ff8175ffe3549f13ebfc6a9e7f (diff) | |
| download | mruby-471479e723157c1a7df2023ab2eea24fa4ca2246.tar.gz mruby-471479e723157c1a7df2023ab2eea24fa4ca2246.zip | |
Change float representation in `mrb` binary files.
From human readable (ASCII) string representation to binary dump of
IEEE754 in little endian.
Diffstat (limited to 'include')
| -rw-r--r-- | include/mruby/endian.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/include/mruby/endian.h b/include/mruby/endian.h new file mode 100644 index 000000000..477f3bc94 --- /dev/null +++ b/include/mruby/endian.h @@ -0,0 +1,44 @@ +/** +** @file mruby/endian.h - detect endian-ness +** +** See Copyright Notice in mruby.h +*/ + +#ifndef MRUBY_ENDIAN_H +#define MRUBY_ENDIAN_H + +#include <limits.h> + +MRB_BEGIN_DECL + +#if !defined(BYTE_ORDER) && defined(__BYTE_ORDER__) +# define BYTE_ORDER __BYTE_ORDER__ +#endif +#if !defined(BIG_ENDIAN) && defined(__ORDER_BIG_ENDIAN__) +# define BIG_ENDIAN __ORDER_BIG_ENDIAN__ +#endif +#if !defined(LITTLE_ENDIAN) && defined(__ORDER_LITTLE_ENDIAN__) +# define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__ +#endif + +#ifdef BYTE_ORDER +# if BYTE_ORDER == BIG_ENDIAN +# define littleendian 0 +# elif BYTE_ORDER == LITTLE_ENDIAN +# define littleendian 1 +# endif +#endif +#ifndef littleendian +/* can't distinguish endian in compile time */ +static inline int +check_little_endian(void) +{ + unsigned int n = 1; + return (*(unsigned char *)&n == 1); +} +# define littleendian check_little_endian() +#endif + +MRB_END_DECL + +#endif /* MRUBY_ENDIAN_H */ |
