All of lore.kernel.org
 help / color / mirror / Atom feed
From: Randy MacLeod <Randy.MacLeod@windriver.com>
To: <linux-modules@vger.kernel.org>
Cc: <randy.macleod@windriver.com>
Subject: [PATCH] kmod-native: Add back-up implementation of be32toh().
Date: Fri, 6 Sep 2013 01:59:01 -0400	[thread overview]
Message-ID: <1378447141-11568-2-git-send-email-Randy.MacLeod@windriver.com> (raw)
In-Reply-To: <1378447141-11568-1-git-send-email-Randy.MacLeod@windriver.com>

Older hosts may not have the be32toh function defined. Check for this and
fall back to checking the endianness and calling bswap_32 directly if needed.
This works on both old and new hosts.

Signed-off-by: Randy MacLeod <Randy.MacLeod@windriver.com>
---
 configure.ac                |  1 +
 libkmod/libkmod-signature.c | 14 +++++++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 40e54cf..de2ee49 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,6 +45,7 @@ PKG_PROG_PKG_CONFIG
 AC_CHECK_FUNCS_ONCE(__xstat)
 AC_CHECK_FUNCS_ONCE([__secure_getenv secure_getenv])
 AC_CHECK_FUNCS_ONCE([finit_module])
+AC_CHECK_FUNCS_ONCE([be32toh])
 
 # dietlibc doesn't have st.st_mtim struct member
 AC_CHECK_MEMBERS([struct stat.st_mtim], [], [], [#include <sys/stat.h>])
diff --git a/libkmod/libkmod-signature.c b/libkmod/libkmod-signature.c
index 6237ab7..791d092 100644
--- a/libkmod/libkmod-signature.c
+++ b/libkmod/libkmod-signature.c
@@ -18,7 +18,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <endian.h>
+#include <byteswap.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
@@ -26,6 +26,18 @@
 
 #include "libkmod-internal.h"
 
+/* be32toh is usually a macro definend in <endian.h>, but it might be
+ * a function in some system so check both, and if neither is defined
+ * then define be32toh (for RHEL 5).
+ */
+#if !defined(HAVE_BE32TOH) && !defined(be32toh)
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define be32toh(x) __bswap_32 (x)
+#else
+#define be32toh(x) (x)
+#endif
+#endif
+
 /* These types and tables were copied from the 3.7 kernel sources.
  * As this is just description of the signature format, it should not be
  * considered derived work (so libkmod can use the LGPL license).
-- 
1.8.2.1


  reply	other threads:[~2013-09-06  5:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-06  5:59 [PATCH] kmod: be32toh for older boxen Randy MacLeod
2013-09-06  5:59 ` Randy MacLeod [this message]
2013-09-06 12:55   ` [PATCH] kmod-native: Add back-up implementation of be32toh() Lucas De Marchi
2013-09-06 13:21     ` Randy MacLeod

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1378447141-11568-2-git-send-email-Randy.MacLeod@windriver.com \
    --to=randy.macleod@windriver.com \
    --cc=linux-modules@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.