From dbcb211376723ca1ed0a87a42dd8a23b388cb7f1 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sat, 26 Oct 2013 12:41:51 -0400 Subject: Remove an endianness assumption. --- driver_zodiac.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) (limited to 'driver_zodiac.c') diff --git a/driver_zodiac.c b/driver_zodiac.c index 3d9bca9c..a62a4a99 100644 --- a/driver_zodiac.c +++ b/driver_zodiac.c @@ -48,32 +48,23 @@ static unsigned short zodiac_checksum(unsigned short *w, int n) return -csum; } -/* zodiac_spew - Takes a message type, an array of data words, and a length - for the array, and prepends a 5 word header (including checksum). - The data words are expected to be checksummed */ -#if defined (WORDS_BIGENDIAN) -/* data is assumed to contain len/2 unsigned short words - * we change the endianness to little, when needed. - */ static int end_write(int fd, void *d, int len) +/* write an array of shorts in little-endian format */ { char buf[BUFSIZ]; char *p = buf; - char *data = (char *)d; - size_t n = (size_t) len; - - while (n > 0) { - *p++ = *(data + 1); - *p++ = *data; - data += 2; - n -= 2; - } + short *data = (short *)d; + size_t n = (size_t)(len/2); + + for (n - 0; n < (size_t)(len/2); n++) + putle16(buf, n*2, data[n]); return write(fd, buf, len); } -#else -#define end_write write -#endif /* WORDS_BIGENDIAN */ +/* zodiac_spew - Takes a message type, an array of data words, and a length + * for the array, and prepends a 5 word header (including checksum). + * The data words are expected to be checksummed. + */ static ssize_t zodiac_spew(struct gps_device_t *session, unsigned short type, unsigned short *dat, int dlen) { -- cgit v1.2.1