From 1adf4453962da0c2ebda1a8833ef3b5b849754e3 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Sun, 22 Jun 2008 22:56:48 +0000 Subject: [PATCH] Added autoconf independent bytesex routines to libgruel. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8654 221aa14e-8319-0410-a670-987f0aec2ac5 --- config/grc_gruel.m4 | 1 + configure.ac | 5 ++- gruel/src/include/gruel/Makefile.am | 4 ++ gruel/src/include/gruel/inet.h.in | 63 +++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 gruel/src/include/gruel/inet.h.in diff --git a/config/grc_gruel.m4 b/config/grc_gruel.m4 index 81f53ce1..0b0dc2c2 100644 --- a/config/grc_gruel.m4 +++ b/config/grc_gruel.m4 @@ -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 \ ]) diff --git a/configure.ac b/configure.ac index f20ca9e4..529d91e7 100644 --- a/configure.ac +++ b/configure.ac @@ -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. diff --git a/gruel/src/include/gruel/Makefile.am b/gruel/src/include/gruel/Makefile.am index 8ea484ce..e5970cc4 100644 --- a/gruel/src/include/gruel/Makefile.am +++ b/gruel/src/include/gruel/Makefile.am @@ -21,7 +21,11 @@ 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 index 00000000..dd052570 --- /dev/null +++ b/gruel/src/include/gruel/inet.h.in @@ -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 . + */ + +#ifndef INCLUDED_INET_H +#define INCLUDED_INET_H + +#include + +#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 +#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 */ -- 2.30.2