[Bug 94570] Use BYTE_ORDER to determine byte order

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Mon Mar 21 12:57:35 UTC 2016


https://bugs.freedesktop.org/show_bug.cgi?id=94570

--- Comment #3 from Jasper Lievisse Adriaanse <jasper at humppa.nl> ---
(In reply to Eduardo Lima (Etrunko) from comment #1)
> --- spice/macros.h.orig	Thu Mar 10 15:14:49 2016
> +++ spice/macros.h	Wed Mar 16 14:18:03 2016
> @@ -381,6 +381,17 @@
>  #define SPICE_ENDIAN_BIG    1234
>  #define SPICE_ENDIAN_PDP    2143
>  
> +/* Lets see if we can use a standard header first... */
> +#if defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) \
> +    && defined(BIG_ENDIAN)
> +#  include <machine/endian.h>
> +#  if BYTE_ORDER == LITTLE_ENDIAN
> +#    define SPICE_ENDIAN SPICE_ENDIAN_LITTLE
> +#  elif BYTE_ORDER == BIG_ENDIAN
> +#    define SPICE_ENDIAN SPICE_ENDIAN_BIG
> +#  endif
> +#endif
> +
> 
> So, instead of relying on those defined macros to include that header, why
> don't you check for it in configure.ac with AC_CHECK_HEADERS macro?
> 
> You would end with something like:
> 
> #if HAVE_MACHINE_ENDIAN_H
>    #include <machine/endian.h>
> ...
> #endif

That won't work out of the box though, as macros.h is a public header. So all
projects that use macros.h would have to explicitly add the AC_CHECK_HEADERS
check for machine/endian.h, no?

Taking your latter comment into account, how about something along these lines?

+#if defined(BYTE_ORDER)
+#  if BYTE_ORDER == LITTLE_ENDIAN
+#    define SPICE_ENDIAN SPICE_ENDIAN_LITTLE
+#  elif BYTE_ORDER == BIG_ENDIAN
+#    define SPICE_ENDIAN SPICE_ENDIAN_BIG
+#  endif
+#endif

This would guard the code in the sense that it won't be evaluated if endian.h
isn't already included through another header.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/spice-bugs/attachments/20160321/c6e22169/attachment.html>


More information about the spice-bugs mailing list