1MEMCHR(3)                  Linux Programmer's Manual                 MEMCHR(3)
2
3
4

NAME

6       memchr, memrchr, rawmemchr - scan memory for a character
7

SYNOPSIS

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

DESCRIPTION

22       The  memchr()  function  scans  the  first  n  bytes of the memory area
23       pointed to by s for the character c.  The first byte to match c (inter‐
24       preted as an unsigned character) stops the operation.
25
26       The  memrchr()  function  is like the memchr() function, except that it
27       searches backwards from the end of the n bytes pointed to by s  instead
28       of forwards from the beginning.
29
30       The  rawmemchr() function is similar to memchr(): it assumes (i.e., the
31       programmer knows for certain) that the character c  lies  somewhere  in
32       the  string  s, and so performs an optimized search for the character c
33       (i.e., no checking for the terminating null byte, or use  of  an  argu‐
34       ment,  n, to limit the range of the search).  If the character c is not
35       in the string s, then rawmemchr() may proceed to search beyond the  end
36       of  the  string, and the result is unspecified.  The folowing call is a
37       fast means of locating a string's terminating null byte:
38
39           char *p = rawmemchr(s, '\0');
40

RETURN VALUE

42       The memchr() and memrchr() functions return a pointer to  the  matching
43       byte or NULL if the character does not occur in the given memory area.
44
45       The rawmemchr() function returns a pointer to the matching byte, if one
46       is found.  If no matching byte is found, the result is unspecified.
47

VERSIONS

49       rawmemchr() first appeared in glibc in version 2.1.
50
51       memrchr() first appeared in glibc in version 2.2.
52

CONFORMING TO

54       The memchr() function conforms to SVr4, 4.3BSD, C89, C99, POSIX.1-2001.
55
56       The memrchr() function  is  a  GNU  extension,  available  since  glibc
57       2.1.91.
58
59       The rawmemchr() function is a GNU extension, available since glibc 2.1.
60

SEE ALSO

62       ffs(3),   index(3),   rindex(3),   strchr(3),  strpbrk(3),  strrchr(3),
63       strsep(3), strspn(3), strstr(3), wmemchr(3)
64

COLOPHON

66       This page is part of release 3.25 of the Linux  man-pages  project.   A
67       description  of  the project, and information about reporting bugs, can
68       be found at http://www.kernel.org/doc/man-pages/.
69
70
71
72                                  2009-12-04                         MEMCHR(3)
Impressum