Forráskód Böngészése

Update ua_config.h.in

added comment for own definition of htoleXX and leXXtoh

check if endian.h is needed

endian.h is included if a htoleXX or leXXtoh definition is missing

better define proposals

improved htoleXX / leXXtoh handling

if the conversion functions are not defined in config.h endian.h is incuded.
if this one does not define the conversion functions the byte order is checked.
if it is little-endian anyway everything is ok. otherwise an error is thrown.

merged overlooked changes
LEvertz 10 éve
szülő
commit
085f5eea88
2 módosított fájl, 24 hozzáadás és 1 törlés
  1. 9 0
      src/ua_config.h.in
  2. 15 1
      src/ua_util.h

+ 9 - 0
src/ua_config.h.in

@@ -29,4 +29,13 @@
 #  endif
 #endif
 
+/*	Define your own htoleXX and leXXtoh here if needed.
+	Otherwise the ones defined in endian.h are used		*/
+//	#define htole16(x)	{...}(x)
+//	#define htole32(x)	{...}(x)
+//	#define htole64(x)	{...}(x)
+//	#define le16toh(x)	{...}(x)
+//	#define le32toh(x)	{...}(x)
+//	#define le64toh(x)	{...}(x)
+
 #endif /* UA_CONFIG_H_ */

+ 15 - 1
src/ua_util.h

@@ -75,7 +75,21 @@
 # undef SLIST_ENTRY
 # define RAND(SEED) (UA_UInt32)rand()
 #else
-# include <endian.h>
+# if !(defined htole16 && defined htole32 && defined htole64 && defined le16toh && defined le32toh && defined le64toh)
+#  include <endian.h>
+#  if !(defined htole16 && defined htole32 && defined htole64 && defined le16toh && defined le32toh && defined le64toh)
+#   if ( __BYTE_ORDER != __LITTLE_ENDIAN )
+#    error "Host byte order is not little-endian and no appropriate conversion functions are defined. (Have a look at ua_config.h)"
+#   else
+#    define htole16(x) x
+#    define htole32(x) x
+#    define htole64(x) x
+#    define le16toh(x) x
+#    define le32toh(x) x
+#    define le64toh(x) x
+#   endif
+#  endif
+# endif
 # include <sys/time.h>
 # define RAND(SEED) (UA_UInt32)rand_r(SEED)
 #endif