From 3f94b73f025f2fa3e08edf07270225c4a5c391c1 Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Thu, 26 May 2011 16:27:43 +0200 Subject: Add host endian detection and endian conversion algorithms --- odb/pgsql/endian-traits.cxx | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 odb/pgsql/endian-traits.cxx (limited to 'odb/pgsql/endian-traits.cxx') diff --git a/odb/pgsql/endian-traits.cxx b/odb/pgsql/endian-traits.cxx new file mode 100644 index 0000000..6730912 --- /dev/null +++ b/odb/pgsql/endian-traits.cxx @@ -0,0 +1,29 @@ +// file : odb/pgsql/endian-traits.cxx +// author : Constantin Michael +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#include + +namespace odb +{ + namespace pgsql + { + namespace + { + endian_traits::endian + infer_host_endian () + { + short s (1); + char* c (reinterpret_cast (&s)); + + return *c == 0 ? + endian_traits::big_endian : + endian_traits::little_endian; + } + } + + const endian_traits::endian endian_traits::host_endian ( + infer_host_endian ()); + } +} -- cgit v1.1