fio: factor out endian_check
authorStephen M. Cameron <stephenmcameron@gmail.com>
Fri, 24 Feb 2012 07:17:31 +0000 (08:17 +0100)
committerJens Axboe <axboe@kernel.dk>
Fri, 24 Feb 2012 07:17:31 +0000 (08:17 +0100)
Signed-off-by: Stephen M. Cameron <stephenmcameron@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Makefile
endian_check.c [new file with mode: 0644]
endian_check.h [new file with mode: 0644]
fio.c

index 888715e..434ad70 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -17,7 +17,8 @@ SOURCE := gettime.c fio.c ioengines.c init.c stat.c log.c time.c filesetup.c \
                rbtree.c smalloc.c filehash.c profile.c debug.c lib/rand.c \
                lib/num2str.c lib/ieee754.c $(wildcard crc/*.c) engines/cpu.c \
                engines/mmap.c engines/sync.c engines/null.c engines/net.c \
-               memalign.c server.c client.c iolog.c backend.c libfio.c flow.c
+               memalign.c server.c client.c iolog.c backend.c libfio.c flow.c \
+               endian_check.c
 
 ifeq ($(UNAME), Linux)
   SOURCE += diskutil.c fifo.c blktrace.c helpers.c cgroup.c trim.c \
diff --git a/endian_check.c b/endian_check.c
new file mode 100644 (file)
index 0000000..c6fc3e2
--- /dev/null
@@ -0,0 +1,33 @@
+#include <stdint.h>
+#include "os/os.h"
+
+int endian_check(void)
+{
+       union {
+               uint8_t c[8];
+               uint64_t v;
+       } u;
+       int le = 0, be = 0;
+
+       u.v = 0x12;
+       if (u.c[7] == 0x12)
+               be = 1;
+       else if (u.c[0] == 0x12)
+               le = 1;
+
+#if defined(FIO_LITTLE_ENDIAN)
+       if (be)
+               return 1;
+#elif defined(FIO_BIG_ENDIAN)
+       if (le)
+               return 1;
+#else
+       return 1;
+#endif
+
+       if (!le && !be)
+               return 1;
+
+       return 0;
+}
+
diff --git a/endian_check.h b/endian_check.h
new file mode 100644 (file)
index 0000000..2e06c3b
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef ENDIAN_CHECK_H
+#define ENDIAN_CHECK_H
+
+int endian_check(void);
+
+#endif 
diff --git a/fio.c b/fio.c
index 2ca4fe6..99d6209 100644 (file)
--- a/fio.c
+++ b/fio.c
 #include "memalign.h"
 #include "client.h"
 #include "server.h"
+#include "endian_check.h"
 
 unsigned long page_mask;
 unsigned long page_size;
 
-static int endian_check(void)
-{
-       union {
-               uint8_t c[8];
-               uint64_t v;
-       } u;
-       int le = 0, be = 0;
-
-       u.v = 0x12;
-       if (u.c[7] == 0x12)
-               be = 1;
-       else if (u.c[0] == 0x12)
-               le = 1;
-
-#if defined(FIO_LITTLE_ENDIAN)
-       if (be)
-               return 1;
-#elif defined(FIO_BIG_ENDIAN)
-       if (le)
-               return 1;
-#else
-       return 1;
-#endif
-
-       if (!le && !be)
-               return 1;
-
-       return 0;
-}
-
 int main(int argc, char *argv[], char *envp[])
 {
        long ps;