Added autoconf independent bytesex routines to libgruel.
authorjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Sun, 22 Jun 2008 22:56:48 +0000 (22:56 +0000)
committerjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Sun, 22 Jun 2008 22:56:48 +0000 (22:56 +0000)
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8654 221aa14e-8319-0410-a670-987f0aec2ac5

config/grc_gruel.m4
configure.ac
gruel/src/include/gruel/Makefile.am
gruel/src/include/gruel/inet.h.in [new file with mode: 0644]

index 81f53ce138ddd07b0571e02f9bbe687dbae63c4e..0b0dc2c2b058562fffa0cf18040780dadd128bcc 100644 (file)
@@ -37,6 +37,7 @@ AC_DEFUN([GRC_GRUEL],[
         gruel/src/Makefile \
         gruel/src/include/Makefile \
         gruel/src/include/gruel/Makefile \
+       gruel/src/include/gruel/inet.h \
         gruel/src/lib/Makefile \
     ])
 
index f20ca9e4e99c670fac53c2e2c4f1660bcb8cc5e0..529d91e77ea18ee59b0836f64a54dc7bdf8c0bd0 100644 (file)
@@ -128,13 +128,16 @@ AC_CHECK_HEADERS(linux/ppdev.h dev/ppbus/ppi.h sys/mman.h sys/select.h sys/types
 AC_CHECK_HEADERS(sys/resource.h stdint.h sched.h signal.h sys/syscall.h)
 AC_CHECK_HEADERS(netinet/in.h)
 AC_CHECK_HEADERS(windows.h)
+AC_CHECK_HEADER(byteswap.h, [GR_HAVE_BYTESWAP=1],[GR_HAVE_BYTESWAP=0])
+AC_SUBST(GR_HAVE_BYTESWAP)
 
 dnl Checks for typedefs, structures, and compiler characteristics.
 AC_C_CONST
 AC_C_INLINE
 AC_TYPE_SIZE_T
 AC_HEADER_TIME
-AC_C_BIGENDIAN
+AC_C_BIGENDIAN([GR_ARCH_BIGENDIAN=1],[GR_ARCH_BIGENDIAN=0])
+AC_SUBST(GR_ARCH_BIGENDIAN)
 AC_STRUCT_TM
 
 dnl Checks for library functions.
index 8ea484cede8b4bec74956e7920714fc294139990..e5970cc4924b6cfa262d1754e51e8fc0dcf36a43 100644 (file)
 
 include $(top_srcdir)/Makefile.common
 
+BUILT_SOURCES = \
+       inet.h
+
 gruelincludedir = $(prefix)/include/gruel
 
 gruelinclude_HEADERS = \
+       $(BUILT_SOURCES) \
        realtime.h
diff --git a/gruel/src/include/gruel/inet.h.in b/gruel/src/include/gruel/inet.h.in
new file mode 100644 (file)
index 0000000..dd05257
--- /dev/null
@@ -0,0 +1,63 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef INCLUDED_INET_H
+#define INCLUDED_INET_H
+
+#include <stdint.h>
+
+#if @GR_ARCH_BIGENDIAN@  /* GR_ARCH_BIGENDIAN */
+// Nothing to do...
+static inline uint32_t htonl(uint32_t x){ return x; }
+static inline uint16_t htons(uint16_t x){ return x; }
+static inline uint32_t ntohl(uint32_t x){ return x; }
+static inline uint16_t ntohs(uint16_t x){ return x; }
+#else
+#if @GR_HAVE_BYTESWAP@  /* GR_HAVE_BYTESWAP */
+#include <byteswap.h>
+#else
+#warning Using non-portable code (likely wrong other than ILP32).
+
+static inline unsigned short int
+bswap_16 (unsigned short int x)
+{
+  return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8));
+}
+
+static inline unsigned int
+bswap_32 (unsigned int x)
+{
+  return ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >>  8)      \
+       | (((x) & 0x0000ff00) <<  8) | (((x) & 0x000000ff) << 24));
+}
+#endif /* GR_HAVE_BYTESWAP */
+
+static inline uint32_t htonl(uint32_t x){ return bswap_32(x); }
+static inline uint16_t htons(uint16_t x){ return bswap_16(x); }
+static inline uint32_t ntohl(uint32_t x){ return bswap_32(x); }
+static inline uint16_t ntohs(uint16_t x){ return bswap_16(x); }
+#endif /* GR_ARCH_BIGENDIAN */
+
+static inline uint8_t  ntohx(uint8_t  x){ return x;        }
+static inline uint16_t ntohx(uint16_t x){ return ntohs(x); }
+static inline uint32_t ntohx(uint32_t x){ return ntohl(x); }
+static inline uint8_t  htonx(uint8_t  x){ return x;        }
+static inline uint16_t htonx(uint16_t x){ return htons(x); }
+static inline uint32_t htonx(uint32_t x){ return htonl(x); }
+
+#endif /* INCLUDED_INET_H */