From 546b293cb9369c9c421981c71577af29d83b925a Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 21 Jul 2014 19:56:53 -0500 Subject: Little endian and big endian versions of peek (for host.c). --- lib/lib.c | 38 ++++++++++++++++++++++++-------------- lib/lib.h | 4 +++- 2 files changed, 27 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/lib/lib.c b/lib/lib.c index bda69931..e16873f0 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -372,21 +372,31 @@ void msleep(long miliseconds) nanosleep(&ts, &ts); } -int64_t peek(void *ptr, int size) +// Inefficient, but deals with unaligned access +int64_t peek_le(void *ptr, unsigned size) { - if (size & 8) { - volatile int64_t *p = (int64_t *)ptr; - return *p; - } else if (size & 4) { - volatile int *p = (int *)ptr; - return *p; - } else if (size & 2) { - volatile short *p = (short *)ptr; - return *p; - } else { - volatile char *p = (char *)ptr; - return *p; - } + int64_t ret = 0; + char *c = ptr; + int i; + + for (i=0; i