1memchr(3)                  Library Functions Manual                  memchr(3)
2
3
4

NAME

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

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <string.h>
13
14       void *memchr(const void s[.n], int c, size_t n);
15       void *memrchr(const void s[.n], int c, size_t n);
16
17       [[deprecated]] void *rawmemchr(const void *s, int c);
18
19   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
20
21       memrchr(), rawmemchr():
22           _GNU_SOURCE
23

DESCRIPTION

25       The  memchr()  function  scans  the  initial n bytes of the memory area
26       pointed to by s for the first instance of c.  Both c and the  bytes  of
27       the memory area pointed to by s are interpreted as unsigned char.
28
29       The  memrchr()  function  is like the memchr() function, except that it
30       searches backward from the end of the n bytes pointed to by  s  instead
31       of forward from the beginning.
32
33       The  rawmemchr() function is similar to memchr(), but it assumes (i.e.,
34       the programmer knows for certain) that an instance of c lies  somewhere
35       in the memory area starting at the location pointed to by s.  If an in‐
36       stance of c is not  found,  the  behavior  is  undefined.   Use  either
37       strlen(3) or memchr(3) instead.
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.
44

ATTRIBUTES

46       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
47       tributes(7).
48
49       ┌────────────────────────────────────────────┬───────────────┬─────────┐
50Interface                                   Attribute     Value   
51       ├────────────────────────────────────────────┼───────────────┼─────────┤
52memchr(), memrchr(), rawmemchr()            │ Thread safety │ MT-Safe │
53       └────────────────────────────────────────────┴───────────────┴─────────┘
54

STANDARDS

56       memchr()
57              C11, POSIX.1-2008.
58
59       memrchr()
60       rawmemchr()
61              GNU.
62

HISTORY

64       memchr()
65              POSIX.1-2001, C89, SVr4, 4.3BSD.
66
67       memrchr()
68              glibc 2.2.
69
70       rawmemchr()
71              glibc 2.1.
72

SEE ALSO

74       bstring(3),   ffs(3),  memmem(3),  strchr(3),  strpbrk(3),  strrchr(3),
75       strsep(3), strspn(3), strstr(3), wmemchr(3)
76
77
78
79Linux man-pages 6.05              2023-07-20                         memchr(3)
Impressum