From eb5c2cc01dbd5756790860ad5eb2302f911d9dc7 Mon Sep 17 00:00:00 2001 From: Steven Fuller Date: Mon, 30 Jul 2001 05:22:12 +0000 Subject: Tools for testing. --- src/tools/util.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/tools/util.c (limited to 'src/tools/util.c') 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 +#include +#include +#include +#include + +#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; +} -- cgit v1.3