aboutsummaryrefslogtreecommitdiffstats
path: root/memsetelem.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-06-10 20:34:32 +0200
committerMattias Andrée <maandree@kth.se>2022-06-10 20:34:32 +0200
commit056c5fe698f194c3187b9eec5378c441930c005b (patch)
treefc918970dcb3576774754c990af230b4dbab02e9 /memsetelem.c
parentAdd strto[u]{hh,h,z}, strto{i,u}{,8,16,32,64} (diff)
downloadlibsimple-056c5fe698f194c3187b9eec5378c441930c005b.tar.gz
libsimple-056c5fe698f194c3187b9eec5378c441930c005b.tar.bz2
libsimple-056c5fe698f194c3187b9eec5378c441930c005b.tar.xz
Remove `static` from some `static inline`
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--memsetelem.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/memsetelem.c b/memsetelem.c
new file mode 100644
index 0000000..6bcf021
--- /dev/null
+++ b/memsetelem.c
@@ -0,0 +1,50 @@
+/* See LICENSE file for copyright and license details. */
+#include "libsimple.h"
+#ifndef TEST
+
+
+extern inline void *libsimple_memsetelem(void *, const void *, size_t, size_t);
+
+
+#else
+#include "test.h"
+
+int
+main(void)
+{
+ char p_[4096];
+ char *p = p_;
+ size_t i;
+
+ memset(p, 0, sizeof(p_));
+ assert(libsimple_memsetelem(p, &(uint64_t){~0}, 0, 0) == p);
+ assert(libsimple_memsetelem(p, &(uint64_t){~0}, 0, 10) == p);
+ assert(libsimple_memsetelem(p, &(uint64_t){~0}, 1, 0) == p);
+ assert(libsimple_memsetelem(p, &(uint64_t){~0}, 2, 0) == p);
+ assert(libsimple_memsetelem(p, &(uint64_t){~0}, 4, 0) == p);
+ assert(libsimple_memsetelem(p, &(uint64_t){~0}, 8, 0) == p);
+ assert(libsimple_memsetelem(p, &(uint64_t){~0}, 16, 0) == p);
+ assert(libsimple_memsetelem(p, &(uint64_t){~0}, 3, 0) == p);
+ assert(libsimple_memsetelem(p, &(uint8_t){0x09}, 1, 3000) == p);
+ assert(libsimple_memsetelem(p, &(uint16_t){0x0807}, 2, 1000) == p);
+ assert(libsimple_memsetelem(p, &(uint32_t){0x10203040UL}, 4, 300) == p);
+ assert(libsimple_memsetelem(p, &(uint64_t){0x0102030450607080ULL}, 8, 100) == p);
+ assert(libsimple_memsetelem(p, (char []){0xA0, 0xB0, 0xC0}, 3, 16) == p);
+
+ for (i = 0; i < 48; i++)
+ assert(p[i] == ((char []){0xA0, 0xB0, 0xC0})[i % 3]);
+ for (; i < 800; i += 8)
+ assert(*(uint64_t *)&p[i] == 0x0102030450607080ULL);
+ for (; i < 1200; i += 4)
+ assert(*(uint32_t *)&p[i] == 0x10203040UL);
+ for (; i < 2000; i += 2)
+ assert(*(uint16_t *)&p[i] == 0x0807);
+ for (; i < 3000; i++)
+ assert(p[i] == 0x09);
+ for (; i < sizeof(p_); i++)
+ assert(p[i] == 0);
+
+ return 0;
+}
+
+#endif