aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libsimple/mem.h2
-rw-r--r--memelem.c11
-rw-r--r--mempsetelem.c6
-rw-r--r--memrelem.c8
4 files changed, 19 insertions, 8 deletions
diff --git a/libsimple/mem.h b/libsimple/mem.h
index 7a7f7ce..57a1f2b 100644
--- a/libsimple/mem.h
+++ b/libsimple/mem.h
@@ -420,7 +420,7 @@ void *libsimple_mempsetelem(void *__buf, const void *__item, size_t __size, size
* @return `buf`
*/
_LIBSIMPLE_GCC_ONLY(__attribute__((__warn_unused_result__)))
-static inline void *libsimple_memsetelem(void *__buf, const void *__item, size_t __size, size_t __nitems)
+static inline void *libsimple_memsetelem(void *__buf, const void *__item, size_t __size, size_t __nitems) /* TODO test */
{ return libsimple_mempsetelem(__buf, __item, __size, __nitems), __buf; }
#ifndef memsetelem
# define memsetelem libsimple_memsetelem
diff --git a/memelem.c b/memelem.c
index ceca578..43cb298 100644
--- a/memelem.c
+++ b/memelem.c
@@ -43,9 +43,14 @@ libsimple_memelem(const void *hay_, size_t hayn, const void *sub_, size_t subn)
{
char *hay = (void *)hay_;
const char *sub = sub_;
- for (; hayn--; hay += subn)
- if (!memcmp(hay, sub, subn))
- return hay;
+ size_t i;
+ for (; hayn--; hay += subn) {
+ for (i = 0; i < subn; i++)
+ if (hay[i] != sub[i])
+ goto next;
+ return hay;
+ next:;
+ }
break;
}
diff --git a/mempsetelem.c b/mempsetelem.c
index d431604..c8990ed 100644
--- a/mempsetelem.c
+++ b/mempsetelem.c
@@ -4,7 +4,7 @@
void *
-libsimple_mempsetelem(void *buf_, const void *item, size_t size, size_t nitems)
+libsimple_mempsetelem(void *buf_, const void *item, size_t size, size_t nitems) /* TODO test */
{
switch (size) {
case 0:
@@ -38,8 +38,10 @@ libsimple_mempsetelem(void *buf_, const void *item, size_t size, size_t nitems)
default:
{
char *buf = buf_;
+ size_t i;
for (; nitems--; buf += size)
- memcpy(buf, item, size);
+ for (i = 0; i < size; i++)
+ buf[i] = ((const char *)item)[i];
return buf;
}
}
diff --git a/memrelem.c b/memrelem.c
index e26ebe6..b1e69ba 100644
--- a/memrelem.c
+++ b/memrelem.c
@@ -50,10 +50,14 @@ libsimple_memrelem(const void *hay_, size_t hayn, const void *sub_, size_t subn)
{
char *hay = (void *)hay_;
const char *sub = sub_;
+ size_t i;
for (hay += hayn * subn; hayn--;) {
hay -= subn;
- if (!memcmp(hay, sub, subn))
- return hay;
+ for (i = 0; i < subn; i++)
+ if (hay[i] != sub[i])
+ goto next;
+ return hay;
+ next:;
}
break;