Do not use htole32 function
htole32 function is not portable enough.
* v4l2.c (print_pixelformat): Rewrite initialization of pixel format
union without using of htole32.
* tests/ioctl_v4l2.c (main): Likewise.
diff --git a/tests/ioctl_v4l2.c b/tests/ioctl_v4l2.c
index 4da8d97..6502b8f 100644
--- a/tests/ioctl_v4l2.c
+++ b/tests/ioctl_v4l2.c
@@ -26,7 +26,6 @@
*/
#include "tests.h"
-#include <endian.h>
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
@@ -58,7 +57,18 @@
const union u_pixel_format {
unsigned int pixelformat;
unsigned char cc[sizeof(int)];
- } u = { .pixelformat = htole32(magic) };
+ } u = {
+#if WORDS_BIGENDIAN
+ .cc = {
+ (unsigned char) (magic >> 24),
+ (unsigned char) (magic >> 16),
+ (unsigned char) (magic >> 8),
+ (unsigned char) magic
+ }
+#else
+ .pixelformat = magic
+#endif
+ };
unsigned int i;
@@ -465,10 +475,19 @@
struct v4l2_frmsizeenum *const p_frmsizeenum =
tail_alloc(sizeof(*p_frmsizeenum));
p_frmsizeenum->index = magic;
- p_frmsizeenum->pixel_format = 0xfa5c2741;
const union u_pixel_format u_frmsizeenum = {
- .pixelformat = htole32(p_frmsizeenum->pixel_format)
+ .cc = { 'A', '\'', '\\', '\xfa' }
};
+#if WORDS_BIGENDIAN
+ p_frmsizeenum->pixel_format =
+ (unsigned) u_frmsizeenum.cc[0] << 24 |
+ (unsigned) u_frmsizeenum.cc[1] << 16 |
+ (unsigned) u_frmsizeenum.cc[2] << 8 |
+ (unsigned) u_frmsizeenum.cc[3];
+#else
+ p_frmsizeenum->pixel_format = u_frmsizeenum.pixelformat;
+#endif
+
ioctl(-1, VIDIOC_ENUM_FRAMESIZES, p_frmsizeenum);
printf("ioctl(-1, VIDIOC_ENUM_FRAMESIZES, {index=%u"
", pixel_format=v4l2_fourcc('%c', '\\%c', '\\%c', '\\x%x')})"
diff --git a/v4l2.c b/v4l2.c
index 62f8810..1df4ca5 100644
--- a/v4l2.c
+++ b/v4l2.c
@@ -77,7 +77,18 @@
const union {
uint32_t pixelformat;
unsigned char cc[sizeof(uint32_t)];
- } u = { .pixelformat = htole32(fourcc) };
+ } u = {
+#if WORDS_BIGENDIAN
+ .cc = {
+ (unsigned char) (fourcc >> 24),
+ (unsigned char) (fourcc >> 16),
+ (unsigned char) (fourcc >> 8),
+ (unsigned char) fourcc
+ }
+#else
+ .pixelformat = fourcc
+#endif
+ };
unsigned int i;
tprints("v4l2_fourcc(");