[Cryptech-Commits] [sw/libhal] 01/03: Move htonl to hal_internal.h

git at cryptech.is git at cryptech.is
Tue May 24 22:04:31 UTC 2016


This is an automated email from the git hooks/post-receive script.

paul at psgd.org pushed a commit to branch master
in repository sw/libhal.

commit 1fe3c1370d668afd68b9c3b6d0e9480bf3700a7e
Author: Paul Selkirk <paul at psgd.org>
AuthorDate: Tue May 24 15:42:15 2016 -0400

    Move htonl to hal_internal.h
---
 hal_internal.h | 21 +++++++++++++++++++++
 hal_io_eim.c   |  1 -
 hal_io_fmc.c   | 15 ---------------
 xdr.c          | 20 +-------------------
 4 files changed, 22 insertions(+), 35 deletions(-)

diff --git a/hal_internal.h b/hal_internal.h
index 253dc09..60aed3b 100644
--- a/hal_internal.h
+++ b/hal_internal.h
@@ -46,6 +46,27 @@
  */
 
 /*
+ * htonl is not available in arm-none-eabi headers or libc.
+ */
+#ifndef STM32F4XX
+#include <arpa/inet.h>
+#else
+#ifdef __ARMEL__                /* little endian */
+inline uint32_t htonl(uint32_t w)
+{
+    return
+        ((w & 0x000000ff) << 24) +
+        ((w & 0x0000ff00) << 8) +
+        ((w & 0x00ff0000) >> 8) +
+        ((w & 0xff000000) >> 24);
+}
+#else                           /* big endian */
+#define htonl(x) (x)
+#endif
+#define ntohl htonl
+#endif
+
+/*
  * Longest hash block and digest we support at the moment.
  */
 
diff --git a/hal_io_eim.c b/hal_io_eim.c
index e353451..173490f 100644
--- a/hal_io_eim.c
+++ b/hal_io_eim.c
@@ -35,7 +35,6 @@
 
 #include <stdio.h>
 #include <stdint.h>
-#include <arpa/inet.h>		/* htonl/ntohl */
 
 #include "novena-eim.h"
 #include "hal.h"
diff --git a/hal_io_fmc.c b/hal_io_fmc.c
index 5629b69..712d9c2 100644
--- a/hal_io_fmc.c
+++ b/hal_io_fmc.c
@@ -47,21 +47,6 @@ static int inited = 0;
 #define FMC_IO_TIMEOUT  100000000
 #endif
 
-/* not available in arm-none-eabi libc */
-#ifdef __ARMEL__    // Little endian
-static inline uint32_t htonl(uint32_t w)
-{
-  return
-    ((w & 0x000000ff) << 24) +
-    ((w & 0x0000ff00) << 8) +
-    ((w & 0x00ff0000) >> 8) +
-    ((w & 0xff000000) >> 24);
-}
-#else               // Big endian
-#define htonl(x) (x)
-#endif
-#define ntohl htonl
-
 static hal_error_t init(void)
 {
   if (!inited) {
diff --git a/xdr.c b/xdr.c
index fa12311..6266d99 100644
--- a/xdr.c
+++ b/xdr.c
@@ -36,26 +36,8 @@
 #include <stdint.h>
 #include <string.h>             /* memcpy, memset */
 
-#ifndef STM32F4XX
-#include <arpa/inet.h>          /* htonl/ntohl */
-#else
-/* htonl is not available in arm-none-eabi headers or libc */
-#ifdef __ARMEL__                /* little endian */
-static inline uint32_t htonl(uint32_t w)
-{
-  return
-    ((w & 0x000000ff) << 24) +
-    ((w & 0x0000ff00) << 8) +
-    ((w & 0x00ff0000) >> 8) +
-    ((w & 0xff000000) >> 24);
-}
-#else
-#define htonl(x) (x)
-#endif
-#define ntohl htonl
-#endif
-
 #include "hal.h"
+#include "hal_internal.h"
 #include "xdr_internal.h"
 
 /* encode/decode_int. This covers int, unsigned int, enum, and bool types,



More information about the Commits mailing list