OSDN Git Service

* safe-ctype.c: #include "ansidecl.h".
[pf3gnuchains/gcc-fork.git] / libiberty / memchr.c
1 /*
2 FUNCTION
3         <<memchr>>---find character in memory
4
5 INDEX
6         memchr
7
8 ANSI_SYNOPSIS
9         #include <string.h>
10         void *memchr(const void *<[src]>, int <[c]>, size_t <[length]>);
11
12 TRAD_SYNOPSIS
13         #include <string.h>
14         void *memchr(<[src]>, <[c]>, <[length]>)
15         void *<[src]>;
16         void *<[c]>;
17         size_t <[length]>;
18
19 DESCRIPTION
20         This function searches memory starting at <<*<[src]>>> for the
21         character <[c]>.  The search only ends with the first
22         occurrence of <[c]>, or after <[length]> characters; in
23         particular, <<NULL>> does not terminate the search.
24
25 RETURNS
26         If the character <[c]> is found within <[length]> characters
27         of <<*<[src]>>>, a pointer to the character is returned. If
28         <[c]> is not found, then <<NULL>> is returned.  
29
30 PORTABILITY
31 <<memchr>>  requires no supporting OS subroutines.
32
33 QUICKREF
34         memchr ansi pure
35
36 */
37
38 #include <ansidecl.h>
39 #ifdef __STDC__
40 #include <stddef.h>
41 #else
42 #define size_t unsigned long
43 #endif
44
45 PTR
46 memchr (src_void, c, length)
47      register const PTR src_void;
48      int c;
49      size_t length;
50 {
51   const unsigned char *src = (const unsigned char *)src_void;
52   
53   while (--length >= 0)
54   {
55     if (*src == c)
56      return (PTR)src;
57     src++;
58   }
59   return NULL;
60 }