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