SGI/IRIX fixes:
- unaligned access in little endian conversion (which was erroneously done)
- detect endianess and set appropriate macro
- detect if CRTSCTS is defined before trying to use it (it's a BSD flag)
- but first detect if the POSIX CCTS_OFLOW is available (hint: it's not on IRIX)
#include <sys/time.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/ioctl.h>
+#if defined(__i386__) || defined(__ia64__) || defined(WIN32) || \
+ (defined(__alpha__) || defined(__alpha)) || \
+ defined(__arm__) || \
+ (defined(__mips__) && defined(__MIPSEL__)) || \
+ defined(__SYMBIAN32__) || \
+ defined(__x86_64__) || \
+ defined(__LITTLE_ENDIAN__)
+#define SBALL_LITTLE_ENDIAN
+#else
+#define SBALL_BIG_ENDIAN
+#endif
+
#define INP_BUF_SZ 256
enum {
#define INP_BUF_SZ 256
enum {
- if(!(sb = malloc(sizeof *sb))) {
+ if(!(sb = calloc(1, sizeof *sb))) {
fprintf(stderr, "sball_open: failed to allocate sball object\n");
goto err;
}
sb->fd = fd;
fprintf(stderr, "sball_open: failed to allocate sball object\n");
goto err;
}
sb->fd = fd;
- sb->flags = 0;
- sb->len = 0;
term.c_cc[VERASE] = 0;
term.c_cc[VKILL] = 0;
term.c_cc[VERASE] = 0;
term.c_cc[VKILL] = 0;
- term.c_cflag = CLOCAL | CREAD | CS8 | CSTOPB | HUPCL | CRTSCTS;
+ term.c_cflag = CLOCAL | CREAD | CS8 | CSTOPB | HUPCL;
+#ifdef CCTS_OFLOW
+ term.c_cflag |= CCTS_OFLOW;
+#elif defined(CRTSCTS)
+ term.c_cflag |= CRTSCTS;
+#endif
term.c_iflag = IGNBRK | IGNPAR;
cfsetispeed(&term, B9600);
term.c_iflag = IGNBRK | IGNPAR;
cfsetispeed(&term, B9600);
}
#ifndef SBALL_BIG_ENDIAN
}
#ifndef SBALL_BIG_ENDIAN
- data += 2;
- c = data[0];
- data[0] = data[1];
- data[1] = c;
- sb->mot[i] = *(short*)data;
+ rd += 2;
+ c = rd[0];
+ rd[0] = rd[1];
+ rd[1] = c;
-#else
- memcpy(sb->mot, data + 2, 12);
+ memcpy(sb->mot, data + 2, 12);
case 'E':
fprintf(stderr, "sball: error:");
for(i=0; i<len; i++) {
case 'E':
fprintf(stderr, "sball: error:");
for(i=0; i<len; i++) {
+ if(isprint((int)data[i])) {
fprintf(stderr, " %c", data[i]);
} else {
fprintf(stderr, " %02xh", (unsigned int)data[i]);
fprintf(stderr, " %c", data[i]);
} else {
fprintf(stderr, " %02xh", (unsigned int)data[i]);