summaryrefslogtreecommitdiffstats
path: root/libgnu
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2017-03-27 10:17:45 +0200
committerUlf Hermann <ulf.hermann@qt.io>2017-05-03 09:26:13 +0000
commitf81bd0a755ee09d7146dc3ab9783677c5dafddf2 (patch)
tree54a60f5c251ea96e90e89b7ad278a6b2f0d80aaf /libgnu
parentf959e18188c5482680d730324b5bd074f6866f96 (diff)
Add endian.h and byteswap.h
Change-Id: I181783e53dba01b00ea53965a325823fb3d58abf Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'libgnu')
-rw-r--r--libgnu/Makefile.am17
-rw-r--r--libgnu/byteswap.in.h38
-rw-r--r--libgnu/endian.in.h75
3 files changed, 129 insertions, 1 deletions
diff --git a/libgnu/Makefile.am b/libgnu/Makefile.am
index 0d31e693..37fdb9ca 100644
--- a/libgnu/Makefile.am
+++ b/libgnu/Makefile.am
@@ -35,7 +35,22 @@ noinst_LIBRARIES =
MOSTLYCLEANFILES =
MOSTLYCLEANDIRS =
BUILT_SOURCES =
-EXTRA_DIST =
+EXTRA_DIST = endian.in.h byteswap.in.h
CLEANFILES =
SUFFIXES =
+
+if !HAVE_ENDIAN_H
+endian.h: endian.in.h
+ $(AM_V_GEN)rm -f $@ && cat $< > $@
+BUILT_SOURCES += endian.h
+MOSTLYCLEANFILES += endian.h
+endif
+
+if !HAVE_BYTESWAP_H
+byteswap.h: byteswap.in.h
+ $(AM_V_GEN)rm -f $@ && cat $< > $@
+BUILT_SOURCES += byteswap.h
+MOSTLYCLEANFILES += byteswap.h
+endif
+
include gnulib.am
diff --git a/libgnu/byteswap.in.h b/libgnu/byteswap.in.h
new file mode 100644
index 00000000..e7b4f29e
--- /dev/null
+++ b/libgnu/byteswap.in.h
@@ -0,0 +1,38 @@
+/* Byteswapping functions for windows
+ Copyright (C) 2017 The Qt Company Ltd.
+ This file is part of elfutils.
+
+ This file is free software; you can redistribute it and/or modify
+ it under the terms of either
+
+ * the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 3 of the License, or (at
+ your option) any later version
+
+ or
+
+ * the GNU General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at
+ your option) any later version
+
+ or both in parallel, as here.
+
+ elfutils is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received copies of the GNU General Public License and
+ the GNU Lesser General Public License along with this program. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef LIB_BYTESWAP_H
+#define LIB_BYTESWAP_H 1
+
+#include <stdlib.h>
+
+#define bswap_16(x) __builtin_bswap16(x)
+#define bswap_32(x) __builtin_bswap32(x)
+#define bswap_64(x) __builtin_bswap64(x)
+
+#endif
diff --git a/libgnu/endian.in.h b/libgnu/endian.in.h
new file mode 100644
index 00000000..c4fa1514
--- /dev/null
+++ b/libgnu/endian.in.h
@@ -0,0 +1,75 @@
+/* Endianness related defines for windows
+ Copyright (C) 2017 The Qt Company Ltd.
+ This file is part of elfutils.
+
+ This file is free software; you can redistribute it and/or modify
+ it under the terms of either
+
+ * the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 3 of the License, or (at
+ your option) any later version
+
+ or
+
+ * the GNU General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at
+ your option) any later version
+
+ or both in parallel, as here.
+
+ elfutils is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received copies of the GNU General Public License and
+ the GNU Lesser General Public License along with this program. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef LIB_ENDIAN_H
+#define LIB_ENDIAN_H 1
+
+#include <sys/param.h>
+
+#define __BYTE_ORDER BYTE_ORDER
+#define __BIG_ENDIAN BIG_ENDIAN
+#define __LITTLE_ENDIAN LITTLE_ENDIAN
+#define __PDP_ENDIAN PDP_ENDIAN
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+
+#define htobe16(x) __builtin_bswap16(x)
+#define htole16(x) (x)
+#define be16toh(x) __builtin_bswap16(x)
+#define le16toh(x) (x)
+
+#define htobe32(x) __builtin_bswap32(x)
+#define htole32(x) (x)
+#define be32toh(x) __builtin_bswap32(x)
+#define le32toh(x) (x)
+
+#define htobe64(x) __builtin_bswap64(x)
+#define htole64(x) (x)
+#define be64toh(x) __builtin_bswap64(x)
+#define le64toh(x) (x)
+
+#elif BYTE_ORDER == BIG_ENDIAN
+
+#define htobe16(x) (x)
+#define htole16(x) __builtin_bswap16(x)
+#define be16toh(x) (x)
+#define le16toh(x) __builtin_bswap16(x)
+
+#define htobe32(x) (x)
+#define htole32(x) __builtin_bswap32(x)
+#define be32toh(x) (x)
+#define le32toh(x) __builtin_bswap32(x)
+
+#define htobe64(x) (x)
+#define htole64(x) __builtin_bswap64(x)
+#define be64toh(x) (x)
+#define le64toh(x) __builtin_bswap64(x)
+
+#endif
+
+#endif // LIB_ENDIAN_H