summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJens Axboe <jens.axboe@oracle.com>2008-05-30 22:17:45 +0200
committerJens Axboe <jens.axboe@oracle.com>2008-05-30 22:17:45 +0200
commit00fb3c8dcbb940338fea9f6cab689b4924266305 (patch)
treec59ec3ae954da20483558853f986ebbb15da99b7 /lib
parent465221b0121f5cf70585d7338c6448ac4b251257 (diff)
downloadfio-00fb3c8dcbb940338fea9f6cab689b4924266305.tar.gz
fio-00fb3c8dcbb940338fea9f6cab689b4924266305.tar.bz2
Move the lib/ stuff around a bit
And actually remember to commit the lib/ files... Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/bswap.h46
-rw-r--r--lib/strsep.c26
-rw-r--r--lib/strsep.h6
3 files changed, 78 insertions, 0 deletions
diff --git a/lib/bswap.h b/lib/bswap.h
new file mode 100644
index 00000000..30fcac54
--- /dev/null
+++ b/lib/bswap.h
@@ -0,0 +1,46 @@
+#ifndef FIO_BSWAP_H
+#define FIO_BSWAP_H
+
+#include <inttypes.h>
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+static inline uint32_t __be32_to_cpu(uint32_t val)
+{
+ uint32_t c1, c2, c3, c4;
+
+ c1 = (val >> 24) & 0xff;
+ c2 = (val >> 16) & 0xff;
+ c3 = (val >> 8) & 0xff;
+ c4 = val & 0xff;
+
+ return c1 | c2 << 8 | c3 << 16 | c4 << 24;
+}
+
+static inline uint64_t __be64_to_cpu(uint64_t val)
+{
+ uint64_t c1, c2, c3, c4, c5, c6, c7, c8;
+
+ c1 = (val >> 56) & 0xff;
+ c2 = (val >> 48) & 0xff;
+ c3 = (val >> 40) & 0xff;
+ c4 = (val >> 32) & 0xff;
+ c5 = (val >> 24) & 0xff;
+ c6 = (val >> 16) & 0xff;
+ c7 = (val >> 8) & 0xff;
+ c8 = val & 0xff;
+
+ return c1 | c2 << 8 | c3 << 16 | c4 << 24 | c5 << 32 | c6 << 40 | c7 << 48 | c8 << 56;
+}
+#else
+static inline uint64_t __be64_to_cpu(uint64_t val)
+{
+ return val;
+}
+
+static inline uint32_t __be32_to_cpu(uint32_t val)
+{
+ return val;
+}
+#endif
+
+#endif
diff --git a/lib/strsep.c b/lib/strsep.c
new file mode 100644
index 00000000..f8e55b53
--- /dev/null
+++ b/lib/strsep.c
@@ -0,0 +1,26 @@
+#include <stdio.h>
+
+char *strsep(char **stringp, const char *delim)
+{
+ char *s;
+ const char *spanp;
+ int c, sc;
+ char *tok;
+
+ if ((s = *stringp) == NULL)
+ return (NULL);
+ for (tok = s;;) {
+ c = *s++;
+ spanp = delim;
+ do {
+ if ((sc = *spanp++) == c) {
+ if (c == 0)
+ s = NULL;
+ else
+ s[-1] = 0;
+ *stringp = s;
+ return (tok);
+ }
+ } while (sc != 0);
+ }
+}
diff --git a/lib/strsep.h b/lib/strsep.h
new file mode 100644
index 00000000..782a3600
--- /dev/null
+++ b/lib/strsep.h
@@ -0,0 +1,6 @@
+#ifndef FIO_LIB_H
+#define FIO_LIB_H
+
+char *strsep(char **, const char *);
+
+#endif