summaryrefslogtreecommitdiff
path: root/driver_zodiac.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2013-10-26 12:41:51 -0400
committerEric S. Raymond <esr@thyrsus.com>2013-10-26 12:41:51 -0400
commitdbcb211376723ca1ed0a87a42dd8a23b388cb7f1 (patch)
tree4d8f28ed55c5fb8f95fbc2bf0c7e10d2a4ea4a4d /driver_zodiac.c
parentcc85119c450a9e4252ad9afba48b3e0bc278477d (diff)
downloadgpsd-dbcb211376723ca1ed0a87a42dd8a23b388cb7f1.tar.gz
Remove an endianness assumption.
Diffstat (limited to 'driver_zodiac.c')
-rw-r--r--driver_zodiac.c29
1 files changed, 10 insertions, 19 deletions
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)
{