Here's a patch for int length issues.  It also stops ttyrec from doing
endianess tests every single time.

-- 
1KB             // Microsoft corollary to Hanlon's razor:
                //      Never attribute to stupidity what can be
                //      adequately explained by malice.
diff -Nurd ttyrec-1.0.6.orig/io.c ttyrec-1.0.6/io.c
--- ttyrec-1.0.6.orig/io.c	2002-10-22 12:01:23.000000000 +0200
+++ ttyrec-1.0.6/io.c	2008-01-25 10:38:56.714689582 +0100
@@ -36,53 +36,32 @@
 #include <assert.h>
 #include <string.h>
 #include <errno.h>
+#include <endian.h>
 
 #include "ttyrec.h"
 
-#define SWAP_ENDIAN(val) ((unsigned int) ( \
-    (((unsigned int) (val) & (unsigned int) 0x000000ffU) << 24) | \
-    (((unsigned int) (val) & (unsigned int) 0x0000ff00U) <<  8) | \
-    (((unsigned int) (val) & (unsigned int) 0x00ff0000U) >>  8) | \
-    (((unsigned int) (val) & (unsigned int) 0xff000000U) >> 24)))
-
-static int 
-is_little_endian ()
-{
-    static int retval = -1;
-
-    if (retval == -1) {
-	int n = 1;
-	char *p = (char *)&n;
-	char x[] = {1, 0, 0, 0};
-
-	assert(sizeof(int) == 4);
-
-	if (memcmp(p, x, 4) == 0) {
-	    retval = 1;
-	} else {
-	    retval = 0;
-	}
-    }
-
-    return retval;
-}
+#define SWAP_ENDIAN(val) ((uint32_t) ( \
+    (((uint32_t) (val) & (uint32_t) 0x000000ffU) << 24) | \
+    (((uint32_t) (val) & (uint32_t) 0x0000ff00U) <<  8) | \
+    (((uint32_t) (val) & (uint32_t) 0x00ff0000U) >>  8) | \
+    (((uint32_t) (val) & (uint32_t) 0xff000000U) >> 24)))
 
-static int
-convert_to_little_endian (int x)
+static int32_t
+convert_to_little_endian (int32_t x)
 {
-    if (is_little_endian()) {
-	return x;
-    } else {
-	return SWAP_ENDIAN(x);
-    }
+#if BYTE_ORDER == LITTLE_ENDIAN
+    return x;
+#else
+    return SWAP_ENDIAN(x);
+#endif
 }
 
 int
 read_header (FILE *fp, Header *h)
 {
-    int buf[3];
+    int32_t buf[3];
 
-    if (fread(buf, sizeof(int), 3, fp) == 0) {
+    if (fread(buf, sizeof(int32_t), 3, fp) == 0) {
 	return 0;
     }
 
@@ -96,13 +75,13 @@
 int
 write_header (FILE *fp, Header *h)
 {
-    int buf[3];
+    int32_t buf[3];
 
     buf[0] = convert_to_little_endian(h->tv.tv_sec);
     buf[1] = convert_to_little_endian(h->tv.tv_usec);
     buf[2] = convert_to_little_endian(h->len);
 
-    if (fwrite(buf, sizeof(int), 3, fp) == 0) {
+    if (fwrite(buf, sizeof(int32_t), 3, fp) == 0) {
 	return 0;
     }
 

Reply via email to