summaryrefslogtreecommitdiff
path: root/src/string/memchr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/string/memchr.c')
-rw-r--r--src/string/memchr.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/string/memchr.c b/src/string/memchr.c
new file mode 100644
index 00000000..97f6b257
--- /dev/null
+++ b/src/string/memchr.c
@@ -0,0 +1,31 @@
+#include <string.h>
+#include "nonstd/assert.h"
+
+/** search memory **/
+void * memchr(const void *s, int c, size_t n)
+{
+ char *p = (char*)s;
+ size_t i = 0;
+
+ ASSERT_NONNULL(s);
+
+ for (i = 0; i < n; i++) {
+ if (p[i] == (unsigned char)c) {
+ return p + i;
+ }
+ }
+
+ /*
+ RETURN_FAILURE(CONSTANT(NULL));
+ RETURN_SUCCESS(a pointer to the located byte);
+ */
+ return NULL;
+}
+
+/***
+searches the first ARGUMENT(n) bytes of memory at ARGUMENT(s) for
+ARGUMENT(c) (converted to an TYPE(unsigned char)).
+***/
+/*
+STDC(1)
+*/