1MEMCHR(3) Linux Programmer's Manual MEMCHR(3)
2
3
4
6 memchr, memrchr, rawmemchr - scan memory for a character
7
9 #include <string.h>
10
11 void *memchr(const void *s, int c, size_t n);
12
13 void *memrchr(const void *s, int c, size_t n);
14
15 void *rawmemchr(const void *s, int c);
16
17 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
18
19 memrchr(), rawmemchr(): _GNU_SOURCE
20
22 The memchr() function scans the initial n bytes of the memory area
23 pointed to by s for the first instance of c. Both c and the bytes of
24 the memory area pointed to by s are interpreted as unsigned char.
25
26 The memrchr() function is like the memchr() function, except that it
27 searches backward from the end of the n bytes pointed to by s instead
28 of forward from the beginning.
29
30 The rawmemchr() function is similar to memchr(): it assumes (i.e., the
31 programmer knows for certain) that an instance of c lies somewhere in
32 the memory area starting at the location pointed to by s, and so per‐
33 forms an optimized search for c (i.e., no use of a count argument to
34 limit the range of the search). If an instance of c is not found, the
35 results are unpredictable. The following call is a fast means of
36 locating a string's terminating null byte:
37
38 char *p = rawmemchr(s, '\0');
39
41 The memchr() and memrchr() functions return a pointer to the matching
42 byte or NULL if the character does not occur in the given memory area.
43
44 The rawmemchr() function returns a pointer to the matching byte, if one
45 is found. If no matching byte is found, the result is unspecified.
46
48 rawmemchr() first appeared in glibc in version 2.1.
49
50 memrchr() first appeared in glibc in version 2.2.
51
53 The memchr() function conforms to SVr4, 4.3BSD, C89, C99, POSIX.1-2001.
54
55 The memrchr() function is a GNU extension, available since glibc
56 2.1.91.
57
58 The rawmemchr() function is a GNU extension, available since glibc 2.1.
59
61 ffs(3), index(3), rindex(3), strchr(3), strpbrk(3), strrchr(3),
62 strsep(3), strspn(3), strstr(3), wmemchr(3)
63
65 This page is part of release 3.53 of the Linux man-pages project. A
66 description of the project, and information about reporting bugs, can
67 be found at http://www.kernel.org/doc/man-pages/.
68
69
70
71 2012-04-23 MEMCHR(3)