File: endianess.c

package info (click to toggle)
ocaml-xiph 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 820 kB
  • sloc: ml: 4,494; ansic: 3,994; makefile: 3
file content (20 lines) | stat: -rw-r--r-- 398 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <caml/memory.h>
#include <stdint.h>

enum
{
    OCAML_MM_LITTLE_ENDIAN = 0x0100,
    OCAML_MM_BIG_ENDIAN = 0x0001,
};

static const union { unsigned char bytes[2]; uint16_t value; } host_order =
    { { 0, 1 } };

CAMLprim value ocaml_mm_is_big_endian(value unit) {
  CAMLparam0();

  if (host_order.value == OCAML_MM_BIG_ENDIAN)
    CAMLreturn(Val_bool(1));

  CAMLreturn(Val_bool(0));
}