]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/memchr.3
prctl.2: Clarify the unsupported hardware case of EINVAL
[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.\"
93015253 5.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
6.\" Permission is granted to make and distribute verbatim copies of this
7.\" manual provided the copyright notice and this permission notice are
8.\" preserved on all copies.
9.\"
10.\" Permission is granted to copy and distribute modified versions of this
11.\" manual under the conditions for verbatim copying, provided that the
12.\" entire resulting derived work is distributed under the terms of a
13.\" permission notice identical to this one.
c13182ef 14.\"
fea681da
MK
15.\" Since the Linux kernel and libraries are constantly changing, this
16.\" manual page may be incorrect or out-of-date. The author(s) assume no
17.\" responsibility for errors or omissions, or for damages resulting from
18.\" the use of the information contained herein. The author(s) may not
19.\" have taken the same level of care in the production of this manual,
20.\" which is licensed free of charge, as they might when working
21.\" professionally.
c13182ef 22.\"
fea681da
MK
23.\" Formatted or processed versions of this manual, if unaccompanied by
24.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 25.\" %%%LICENSE_END
fea681da
MK
26.\"
27.\" Modified Mon Apr 12 12:49:57 1993, David Metcalfe
28.\" Modified Sat Jul 24 18:56:22 1993, Rik Faith (faith@cs.unc.edu)
29.\" Modified Wed Feb 20 21:09:36 2002, Ian Redfern (redferni@logica.com)
2a8bb904 30.\" 2008-07-09, mtk, add rawmemchr()
fea681da 31.\"
9ba01802 32.TH MEMCHR 3 2019-03-06 "" "Linux Programmer's Manual"
fea681da 33.SH NAME
2a8bb904 34memchr, memrchr, rawmemchr \- scan memory for a character
fea681da
MK
35.SH SYNOPSIS
36.nf
37.B #include <string.h>
dbfe9c70 38.PP
fea681da 39.BI "void *memchr(const void *" s ", int " c ", size_t " n );
dbfe9c70 40.PP
fea681da 41.BI "void *memrchr(const void *" s ", int " c ", size_t " n );
dbfe9c70 42.PP
2a8bb904 43.BI "void *rawmemchr(const void *" s ", int " c );
fea681da 44.fi
68e4db0a 45.PP
2a8bb904
MK
46.in -4n
47Feature Test Macro Requirements for glibc (see
48.BR feature_test_macros (7)):
49.in
68e4db0a 50.PP
13a7959b 51.BR memrchr (),
2a8bb904
MK
52.BR rawmemchr ():
53_GNU_SOURCE
fea681da 54.SH DESCRIPTION
c13182ef 55The
63aa9df0 56.BR memchr ()
9640b1b3
MK
57function scans the initial
58.I n
59bytes of the memory
60area pointed to by
61.I s
62for the first instance of
63.IR c .
64Both
65.I c
66and the bytes of the memory area pointed to by
67.I s
68are interpreted as
69.IR "unsigned char" .
fea681da 70.PP
c13182ef 71The
63aa9df0 72.BR memrchr ()
c13182ef 73function is like the
63aa9df0 74.BR memchr ()
fea681da 75function,
9640b1b3
MK
76except that it searches backward from the end of the
77.I n
78bytes pointed to by
79.I s
80instead of forward from the beginning.
847e0d88 81.PP
2a8bb904
MK
82The
83.BR rawmemchr ()
84function is similar to
85.BR memchr ():
86it assumes (i.e., the programmer knows for certain)
9640b1b3 87that an instance of
2a8bb904 88.I c
9640b1b3 89lies somewhere in the memory area starting at the location pointed to by
2a8bb904 90.IR s ,
9640b1b3 91and so performs an optimized search for
e346bc5a 92.IR c
a0d6d887 93(i.e., no use of a count argument to limit the range of the search).
9640b1b3 94If an instance of
2a8bb904 95.I c
9640b1b3 96is not found, the results are unpredictable.
88d95555 97The following call is a fast means of locating a string's
2a8bb904 98terminating null byte:
e646a1ba 99.PP
2a8bb904 100.in +4n
e646a1ba 101.EX
d1a71985 102char *p = rawmemchr(s,\ \(aq\e0\(aq);
b8302363 103.EE
2a8bb904 104.in
47297adb 105.SH RETURN VALUE
60a90ecd
MK
106The
107.BR memchr ()
108and
109.BR memrchr ()
110functions return a pointer
fea681da
MK
111to the matching byte or NULL if the character does not occur in
112the given memory area.
847e0d88 113.PP
2a8bb904
MK
114The
115.BR rawmemchr ()
116function returns a pointer to the matching byte, if one is found.
117If no matching byte is found, the result is unspecified.
781166d1
MK
118.SH VERSIONS
119.BR rawmemchr ()
120first appeared in glibc in version 2.1.
847e0d88 121.PP
781166d1
MK
122.BR memrchr ()
123first appeared in glibc in version 2.2.
daecb330 124.SH ATTRIBUTES
f92bb4d8
PH
125For an explanation of the terms used in this section, see
126.BR attributes (7).
127.TS
128allbox;
129lbw32 lb lb
130l l l.
131Interface Attribute Value
132T{
daecb330
PH
133.BR memchr (),
134.BR memrchr (),
daecb330 135.BR rawmemchr ()
f92bb4d8
PH
136T} Thread safety MT-Safe
137.TE
47297adb 138.SH CONFORMING TO
a3f8daf6
MK
139.BR memchr ():
140POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.
847e0d88 141.PP
c13182ef 142The
63aa9df0 143.BR memrchr ()
fea681da 144function is a GNU extension, available since glibc 2.1.91.
847e0d88 145.PP
2a8bb904 146The
c7cb2bdb 147.BR rawmemchr ()
2a8bb904 148function is a GNU extension, available since glibc 2.1.
47297adb 149.SH SEE ALSO
879091c9 150.BR bstring (3),
52aa4b97 151.BR ffs (3),
fea681da 152.BR index (3),
3924b70d 153.BR memmem (3),
fea681da
MK
154.BR rindex (3),
155.BR strchr (3),
156.BR strpbrk (3),
157.BR strrchr (3),
158.BR strsep (3),
159.BR strspn (3),
160.BR strstr (3),
161.BR wmemchr (3)