summaryrefslogtreecommitdiff
path: root/support/sdbinutils/libiberty/memchr.c
diff options
context:
space:
mode:
authorXavier ASUS <xavi92psx@gmail.com>2019-10-18 00:31:54 +0200
committerXavier ASUS <xavi92psx@gmail.com>2019-10-18 00:31:54 +0200
commit268a53de823a6750d6256ee1fb1e7707b4b45740 (patch)
tree42c1799a9a82b2f7d9790ee9fe181d72a7274751 /support/sdbinutils/libiberty/memchr.c
downloadsdcc-gas-268a53de823a6750d6256ee1fb1e7707b4b45740.tar.gz
sdcc-3.9.0 fork implementing GNU assembler syntax
This fork aims to provide better support for stm8-binutils
Diffstat (limited to 'support/sdbinutils/libiberty/memchr.c')
-rw-r--r--support/sdbinutils/libiberty/memchr.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/support/sdbinutils/libiberty/memchr.c b/support/sdbinutils/libiberty/memchr.c
new file mode 100644
index 0000000..7448ab9
--- /dev/null
+++ b/support/sdbinutils/libiberty/memchr.c
@@ -0,0 +1,33 @@
+/*
+
+@deftypefn Supplemental void* memchr (const void *@var{s}, int @var{c}, @
+ size_t @var{n})
+
+This function searches memory starting at @code{*@var{s}} for the
+character @var{c}. The search only ends with the first occurrence of
+@var{c}, or after @var{length} characters; in particular, a null
+character does not terminate the search. If the character @var{c} is
+found within @var{length} characters of @code{*@var{s}}, a pointer
+to the character is returned. If @var{c} is not found, then @code{NULL} is
+returned.
+
+@end deftypefn
+
+*/
+
+#include <ansidecl.h>
+#include <stddef.h>
+
+PTR
+memchr (register const PTR src_void, int c, size_t length)
+{
+ const unsigned char *src = (const unsigned char *)src_void;
+
+ while (length-- > 0)
+ {
+ if (*src == c)
+ return (PTR)src;
+ src++;
+ }
+ return NULL;
+}