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  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

RETURN VALUE

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

VERSIONS

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

ATTRIBUTES

53       For   an   explanation   of   the  terms  used  in  this  section,  see
54       attributes(7).
55
56       ┌─────────────────────────────────┬───────────────┬─────────┐
57Interface                        Attribute     Value   
58       ├─────────────────────────────────┼───────────────┼─────────┤
59memchr(), memrchr(), rawmemchr() │ Thread safety │ MT-Safe │
60       └─────────────────────────────────┴───────────────┴─────────┘

CONFORMING TO

62       memchr(): POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.
63
64       The memrchr() function  is  a  GNU  extension,  available  since  glibc
65       2.1.91.
66
67       The rawmemchr() function is a GNU extension, available since glibc 2.1.
68

SEE ALSO

70       bstring(3),  ffs(3),  index(3),  memmem(3), rindex(3), strchr(3), strp‐
71       brk(3), strrchr(3), strsep(3), strspn(3), strstr(3), wmemchr(3)
72

COLOPHON

74       This page is part of release 5.02 of the Linux  man-pages  project.   A
75       description  of  the project, information about reporting bugs, and the
76       latest    version    of    this    page,    can     be     found     at
77       https://www.kernel.org/doc/man-pages/.
78
79
80
81                                  2019-03-06                         MEMCHR(3)
Impressum