]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/memchr.3
Many pages: Use correct letter case in page titles (TH)
[thirdparty/man-pages.git] / man3 / memchr.3
CommitLineData
fea681da 1.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2a8bb904
MK
2.\" and Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
3.\" <mtk.manpages@gmail.com>
fea681da 4.\"
5fbde956 5.\" SPDX-License-Identifier: Linux-man-pages-copyleft
fea681da
MK
6.\"
7.\" Modified Mon Apr 12 12:49:57 1993, David Metcalfe
8.\" Modified Sat Jul 24 18:56:22 1993, Rik Faith (faith@cs.unc.edu)
9.\" Modified Wed Feb 20 21:09:36 2002, Ian Redfern (redferni@logica.com)
2a8bb904 10.\" 2008-07-09, mtk, add rawmemchr()
fea681da 11.\"
4c1c5274 12.TH memchr 3 (date) "Linux man-pages (unreleased)"
fea681da 13.SH NAME
2a8bb904 14memchr, memrchr, rawmemchr \- scan memory for a character
0a2adce0
AC
15.SH LIBRARY
16Standard C library
8fc3b2cf 17.RI ( libc ", " \-lc )
fea681da
MK
18.SH SYNOPSIS
19.nf
20.B #include <string.h>
dbfe9c70 21.PP
fea681da 22.BI "void *memchr(const void *" s ", int " c ", size_t " n );
fea681da 23.BI "void *memrchr(const void *" s ", int " c ", size_t " n );
2a8bb904 24.BI "void *rawmemchr(const void *" s ", int " c );
fea681da 25.fi
68e4db0a 26.PP
d39ad78f 27.RS -4
2a8bb904
MK
28Feature Test Macro Requirements for glibc (see
29.BR feature_test_macros (7)):
d39ad78f 30.RE
68e4db0a 31.PP
13a7959b 32.BR memrchr (),
2a8bb904 33.BR rawmemchr ():
1dd0d7b4
MK
34.nf
35 _GNU_SOURCE
36.fi
fea681da 37.SH DESCRIPTION
c13182ef 38The
63aa9df0 39.BR memchr ()
9640b1b3
MK
40function scans the initial
41.I n
42bytes of the memory
43area pointed to by
44.I s
45for the first instance of
46.IR c .
47Both
48.I c
49and the bytes of the memory area pointed to by
50.I s
51are interpreted as
52.IR "unsigned char" .
fea681da 53.PP
c13182ef 54The
63aa9df0 55.BR memrchr ()
c13182ef 56function is like the
63aa9df0 57.BR memchr ()
fea681da 58function,
9640b1b3
MK
59except that it searches backward from the end of the
60.I n
61bytes pointed to by
62.I s
63instead of forward from the beginning.
847e0d88 64.PP
2a8bb904
MK
65The
66.BR rawmemchr ()
67function is similar to
68.BR memchr ():
69it assumes (i.e., the programmer knows for certain)
9640b1b3 70that an instance of
2a8bb904 71.I c
9640b1b3 72lies somewhere in the memory area starting at the location pointed to by
2a8bb904 73.IR s ,
9640b1b3 74and so performs an optimized search for
1ae6b2c7 75.I c
a0d6d887 76(i.e., no use of a count argument to limit the range of the search).
9640b1b3 77If an instance of
2a8bb904 78.I c
9640b1b3 79is not found, the results are unpredictable.
88d95555 80The following call is a fast means of locating a string's
2a8bb904 81terminating null byte:
e646a1ba 82.PP
2a8bb904 83.in +4n
e646a1ba 84.EX
d1a71985 85char *p = rawmemchr(s,\ \(aq\e0\(aq);
b8302363 86.EE
2a8bb904 87.in
47297adb 88.SH RETURN VALUE
60a90ecd
MK
89The
90.BR memchr ()
91and
92.BR memrchr ()
93functions return a pointer
fea681da
MK
94to the matching byte or NULL if the character does not occur in
95the given memory area.
847e0d88 96.PP
2a8bb904
MK
97The
98.BR rawmemchr ()
99function returns a pointer to the matching byte, if one is found.
100If no matching byte is found, the result is unspecified.
781166d1
MK
101.SH VERSIONS
102.BR rawmemchr ()
103first appeared in glibc in version 2.1.
847e0d88 104.PP
781166d1
MK
105.BR memrchr ()
106first appeared in glibc in version 2.2.
daecb330 107.SH ATTRIBUTES
f92bb4d8
PH
108For an explanation of the terms used in this section, see
109.BR attributes (7).
c466875e
MK
110.ad l
111.nh
f92bb4d8
PH
112.TS
113allbox;
c466875e 114lbx lb lb
f92bb4d8
PH
115l l l.
116Interface Attribute Value
117T{
daecb330
PH
118.BR memchr (),
119.BR memrchr (),
daecb330 120.BR rawmemchr ()
f92bb4d8
PH
121T} Thread safety MT-Safe
122.TE
c466875e
MK
123.hy
124.ad
125.sp 1
3113c7f3 126.SH STANDARDS
a3f8daf6
MK
127.BR memchr ():
128POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.
847e0d88 129.PP
c13182ef 130The
63aa9df0 131.BR memrchr ()
fea681da 132function is a GNU extension, available since glibc 2.1.91.
847e0d88 133.PP
2a8bb904 134The
c7cb2bdb 135.BR rawmemchr ()
2a8bb904 136function is a GNU extension, available since glibc 2.1.
47297adb 137.SH SEE ALSO
879091c9 138.BR bstring (3),
52aa4b97 139.BR ffs (3),
fea681da 140.BR index (3),
3924b70d 141.BR memmem (3),
fea681da
MK
142.BR rindex (3),
143.BR strchr (3),
144.BR strpbrk (3),
145.BR strrchr (3),
146.BR strsep (3),
147.BR strspn (3),
148.BR strstr (3),
149.BR wmemchr (3)