]> git.alsa-project.org Git - alsa-lib.git/commitdiff
topology: Quit and show error message on big-endian machines
authorMengdong Lin <mengdong.lin@linux.intel.com>
Thu, 19 Nov 2015 08:33:12 +0000 (03:33 -0500)
committerTakashi Iwai <tiwai@suse.de>
Thu, 19 Nov 2015 09:17:45 +0000 (10:17 +0100)
This tool can only support little-endian machines atm.
Many codes directly refer to  __le32/__le64 variables of ABI objects,
so will be broken on big-endian machines.

Signed-off-by: Mengdong Lin <mengdong.lin@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
src/topology/parser.c
src/topology/tplg_local.h

index e6798be9b79abf7598f1b979600d5139bb6f97b1..45462577e71c02f6ea12e30bc40343c3b9f610db 100644 (file)
@@ -371,10 +371,25 @@ void snd_tplg_verbose(snd_tplg_t *tplg, int verbose)
        tplg->verbose = verbose;
 }
 
+static bool is_little_endian(void)
+{
+#ifdef __BYTE_ORDER
+       #if __BYTE_ORDER == __LITTLE_ENDIAN
+               return true;
+       #endif
+#endif
+       return false;
+}
+
 snd_tplg_t *snd_tplg_new(void)
 {
        snd_tplg_t *tplg;
 
+       if (!is_little_endian()) {
+               SNDERR("error: cannot support big-endian machines\n");
+               return NULL;
+       }
+
        tplg = calloc(1, sizeof(snd_tplg_t));
        if (!tplg)
                return NULL;
index 06cb1005760c391d069b9a80fa9c36ce1fe7416f..e66d7f4e2d732a43ae68ce814c307f667ff2856a 100644 (file)
@@ -12,6 +12,8 @@
 
 #include <limits.h>
 #include <stdint.h>
+#include <stdbool.h>
+#include <endian.h>
 #include <linux/types.h>
 
 #include "local.h"