Sisyphus repository
Last update: 1 october 2023 | SRPMs: 18631 | Visits: 37601474
en ru br
ALT Linux repos
S:1.0.8-alt3

Group :: Terminals
RPM: ttyrec

 Main   Changelog   Spec   Patches   Sources   Download   Gear   Bugs and FR  Repocop 

Patch: 04_64-bit.diff
Download


Description: 64-bit support
Authors: Adam Borowski <kilobyte@angband.pl> and NIIBE Yutaka <gniibe@fsij.org>
Bug-Debian: http://bugs.debian.org/154520
Reviewed-By: NIIBE Yutaka <gniibe@fsij.org>
Last-Update: 2010-04-27
--- ttyrec-1.0.8.orig/io.c
+++ ttyrec-1.0.8/io.c
@@ -33,6 +33,8 @@
 
 #include <assert.h>
 #include <errno.h>
+#include <endian.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -40,50 +42,28 @@
 
 #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;
-}
-
-static int
-convert_to_little_endian (int x)
-{
-    if (is_little_endian()) {
-	return x;
-    } else {
-	return SWAP_ENDIAN(x);
-    }
+#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 uint32_t
+convert_to_little_endian (uint32_t x)
+{
+#if BYTE_ORDER == LITTLE_ENDIAN
+  return x;
+#else
+  return SWAP_ENDIAN(x);
+#endif
 }
 
 int
 read_header (FILE *fp, Header *h)
 {
-    int buf[3];
+    uint32_t buf[3];
 
-    if (fread(buf, sizeof(int), 3, fp) == 0) {
+    if (fread(buf, sizeof(uint32_t), 3, fp) == 0) {
 	return 0;
     }
 
@@ -97,13 +77,13 @@
 int
 write_header (FILE *fp, Header *h)
 {
-    int buf[3];
+    uint32_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(uint32_t), 3, fp) == 0) {
 	return 0;
     }
 
@@ -158,4 +138,5 @@
 	fprintf(stderr, "%s: fdopen failed: %s\n", progname, strerror(errno));
 	exit(EXIT_FAILURE);
     }
+    return fp;
 }
 
design & coding: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
current maintainer: Michael Shigorin