summaryrefslogtreecommitdiffstats
path: root/libiberty/memchr.c
diff options
context:
space:
mode:
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>1997-08-21 22:57:35 +0000
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>1997-08-21 22:57:35 +0000
commit28e9041cc224267271fbcd8db22bea115912365b (patch)
treea3b19970338bdae580faff126a716e1d5520400c /libiberty/memchr.c
parent5000a677980ebfb439f5349c5e269f7447dbab41 (diff)
downloadppe42-gcc-28e9041cc224267271fbcd8db22bea115912365b.tar.gz
ppe42-gcc-28e9041cc224267271fbcd8db22bea115912365b.zip
Initial revision
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@14877 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libiberty/memchr.c')
-rw-r--r--libiberty/memchr.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/libiberty/memchr.c b/libiberty/memchr.c
new file mode 100644
index 00000000000..93ef43d3f88
--- /dev/null
+++ b/libiberty/memchr.c
@@ -0,0 +1,60 @@
+/*
+FUNCTION
+ <<memchr>>---find character in memory
+
+INDEX
+ memchr
+
+ANSI_SYNOPSIS
+ #include <string.h>
+ void *memchr(const void *<[src]>, int <[c]>, size_t <[length]>);
+
+TRAD_SYNOPSIS
+ #include <string.h>
+ void *memchr(<[src]>, <[c]>, <[length]>)
+ void *<[src]>;
+ void *<[c]>;
+ size_t <[length]>;
+
+DESCRIPTION
+ This function searches memory starting at <<*<[src]>>> for the
+ character <[c]>. The search only ends with the first
+ occurrence of <[c]>, or after <[length]> characters; in
+ particular, <<NULL>> does not terminate the search.
+
+RETURNS
+ If the character <[c]> is found within <[length]> characters
+ of <<*<[src]>>>, a pointer to the character is returned. If
+ <[c]> is not found, then <<NULL>> is returned.
+
+PORTABILITY
+<<memchr>> requires no supporting OS subroutines.
+
+QUICKREF
+ memchr ansi pure
+
+*/
+
+#include <ansidecl.h>
+#ifdef __STDC__
+#include <stddef.h>
+#else
+#define size_t unsigned long
+#endif
+
+PTR
+memchr (src_void, c, length)
+ 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;
+}
OpenPOWER on IntegriCloud