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       void *memrchr(const void *s, int c, size_t n);
13       void *rawmemchr(const void *s, int c);
14
15   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
16
17       memrchr(), rawmemchr():
18           _GNU_SOURCE
19

DESCRIPTION

21       The  memchr()  function  scans  the  initial n bytes of the memory area
22       pointed to by s for the first instance of c.  Both c and the  bytes  of
23       the memory area pointed to by s are interpreted as unsigned char.
24
25       The  memrchr()  function  is like the memchr() function, except that it
26       searches backward from the end of the n bytes pointed to by  s  instead
27       of forward from the beginning.
28
29       The  rawmemchr() function is similar to memchr(): it assumes (i.e., the
30       programmer knows for certain) that an instance of c lies  somewhere  in
31       the  memory  area starting at the location pointed to by s, and so per‐
32       forms an optimized search for c (i.e., no use of a  count  argument  to
33       limit  the range of the search).  If an instance of c is not found, the
34       results are unpredictable.  The following call is a fast means  of  lo‐
35       cating a string's terminating null byte:
36
37           char *p = rawmemchr(s, '\0');
38

RETURN VALUE

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

VERSIONS

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

ATTRIBUTES

52       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
53       tributes(7).
54
55       ┌────────────────────────────────────────────┬───────────────┬─────────┐
56Interface                                   Attribute     Value   
57       ├────────────────────────────────────────────┼───────────────┼─────────┤
58memchr(), memrchr(), rawmemchr()            │ Thread safety │ MT-Safe │
59       └────────────────────────────────────────────┴───────────────┴─────────┘
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.13 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                                  2021-03-22                         MEMCHR(3)
Impressum