summaryrefslogtreecommitdiff
path: root/src/tools/util.c
diff options
context:
space:
mode:
authorSteven Fuller <relnev@icculus.org>2001-07-30 05:22:12 +0000
committerPatryk Obara <dreamer.tan@gmail.com>2019-08-20 02:22:36 +0200
commiteb5c2cc01dbd5756790860ad5eb2302f911d9dc7 (patch)
tree2928560dd46bce280d95e549069a7130dcccd1c1 /src/tools/util.c
parentf097dd925866f7a25c9fa58dcf46b4fc59302cb6 (diff)
Tools for testing.
Diffstat (limited to 'src/tools/util.c')
-rw-r--r--src/tools/util.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/tools/util.c b/src/tools/util.c
new file mode 100644
index 0000000..3c1f5aa
--- /dev/null
+++ b/src/tools/util.c
@@ -0,0 +1,90 @@
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdint.h>
+
+#include "util.h"
+
+int32_t ReadInt32M(FILE *fp)
+{
+ unsigned char d[4];
+
+ fread(d, 1, 4, fp);
+
+ return (d[0] << 24) | (d[1] << 16) | (d[2] << 8) | (d[3] << 0);
+}
+
+int32_t ReadInt24M(FILE *fp)
+{
+ unsigned char d[3];
+
+ fread(d, 1, 3, fp);
+
+ return (d[0] << 16) | (d[1] << 8) | (d[2] << 0);
+}
+
+int16_t ReadInt16M(FILE *fp)
+{
+ unsigned char d[2];
+
+ fread(d, 1, 2, fp);
+
+ return (d[0] << 8) | (d[1] << 0);
+}
+
+int32_t ReadInt32L(FILE *fp)
+{
+ unsigned char d[4];
+
+ fread(d, 1, 4, fp);
+
+ return (d[3] << 24) | (d[2] << 16) | (d[1] << 8) | (d[0] << 0);
+}
+
+int32_t ReadInt24L(FILE *fp)
+{
+ unsigned char d[3];
+
+ fread(d, 1, 3, fp);
+
+ return (d[2] << 16) | (d[1] << 8) | (d[0] << 0);
+}
+
+int16_t ReadInt16L(FILE *fp)
+{
+ unsigned char d[2];
+
+ fread(d, 1, 2, fp);
+
+ return (d[1] << 8) | (d[0] << 0);
+}
+
+int8_t ReadInt8(FILE *fp)
+{
+ unsigned char d[1];
+
+ fread(d, 1, 1, fp);
+
+ return d[0];
+}
+
+int filelength(int filedes)
+{
+ struct stat buf;
+
+ if (fstat(filedes, &buf) == -1)
+ return -1;
+
+ return buf.st_size;
+}
+
+int fsize(char *file_name)
+{
+ struct stat buf;
+
+ if (stat(file_name, &buf) == -1)
+ return -1;
+
+ return buf.st_size;
+}