Debian Codegraph @

upstream/mageia-cauldron/man3/memchr.3

raw
1 '\" t
2 .\" Copyright 1993, David Metcalfe <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH memchr 3 2026-02-08 "Linux man-pages 6.17"
8 .SH NAME
9 memchr, memrchr, rawmemchr \- scan memory for a character
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ,\~ \-lc )
13 .SH SYNOPSIS
14 .nf
15 .B #include <string.h>
16 .P
17 .BR "void *memchr(" "size_t n;"
18 .BI " const void " s [ n "], int " c ", size_t " n );
19 .BR "void *memrchr(" "size_t n;"
20 .BI " const void " s [ n "], int " c ", size_t " n );
21 .P
22 .BI "[[deprecated]] void *rawmemchr(const void *" s ", int " c );
23 .fi
24 .P
25 .RS -4
26 Feature Test Macro Requirements for glibc (see
27 .BR feature_test_macros (7)):
28 .RE
29 .P
30 .BR memrchr (),
31 .BR rawmemchr ():
32 .nf
33 _GNU_SOURCE
34 .fi
35 .SH DESCRIPTION
36 The
37 .BR memchr ()
38 function scans the initial
39 .I n
40 bytes of the memory
41 area pointed to by
42 .I s
43 for the first instance of
44 .IR c .
45 Both
46 .I c
47 and the bytes of the memory area pointed to by
48 .I s
49 are interpreted as
50 .IR "unsigned char" .
51 .P
52 The
53 .BR memrchr ()
54 function is like the
55 .BR memchr ()
56 function,
57 except that it searches backward from the end of the
58 .I n
59 bytes pointed to by
60 .I s
61 instead of forward from the beginning.
62 .P
63 The
64 .BR rawmemchr ()
65 function is similar to
66 .BR memchr (),
67 but it assumes
68 (i.e., the programmer knows for certain)
69 that an instance of
70 .I c
71 lies somewhere in the memory area starting at the location pointed to by
72 .IR s .
73 If an instance of
74 .I c
75 is not found, the behavior is undefined.
76 Use either
77 .BR strlen (3)
78 or
79 .BR memchr (3)
80 instead.
81 .SH RETURN VALUE
82 The
83 .BR memchr ()
84 and
85 .BR memrchr ()
86 functions return a pointer
87 to the matching byte or NULL if the character does not occur in
88 the given memory area.
89 .P
90 The
91 .BR rawmemchr ()
92 function returns a pointer to the matching byte.
93 .SH ATTRIBUTES
94 For an explanation of the terms used in this section, see
95 .BR attributes (7).
96 .TS
97 allbox;
98 lbx lb lb
99 l l l.
100 Interface Attribute Value
101 T{
102 .na
103 .nh
104 .BR memchr (),
105 .BR memrchr (),
106 .BR rawmemchr ()
107 T} Thread safety MT-Safe
108 .TE
109 .SH STANDARDS
110 .TP
111 .BR memchr ()
112 C11, POSIX.1-2008.
113 .TP
114 .BR memrchr ()
115 .TQ
116 .BR rawmemchr ()
117 GNU.
118 .SH HISTORY
119 .TP
120 .BR memchr ()
121 POSIX.1-2001, C89, SVr4, 4.3BSD.
122 .TP
123 .BR memrchr ()
124 glibc 2.2.
125 .TP
126 .BR rawmemchr ()
127 glibc 2.1.
128 .SH SEE ALSO
129 .BR bstring (3),
130 .BR ffs (3),
131 .BR memmem (3),
132 .BR strchr (3),
133 .BR strpbrk (3),
134 .BR strrchr (3),
135 .BR strsep (3),
136 .BR strspn (3),
137 .BR strstr (3),
138 .BR wmemchr (3)