]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/memchr.3
memchr.3: spfix
[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
MK
4.\"
5.\" Permission is granted to make and distribute verbatim copies of this
6.\" manual provided the copyright notice and this permission notice are
7.\" preserved on all copies.
8.\"
9.\" Permission is granted to copy and distribute modified versions of this
10.\" manual under the conditions for verbatim copying, provided that the
11.\" entire resulting derived work is distributed under the terms of a
12.\" permission notice identical to this one.
c13182ef 13.\"
fea681da
MK
14.\" Since the Linux kernel and libraries are constantly changing, this
15.\" manual page may be incorrect or out-of-date. The author(s) assume no
16.\" responsibility for errors or omissions, or for damages resulting from
17.\" the use of the information contained herein. The author(s) may not
18.\" have taken the same level of care in the production of this manual,
19.\" which is licensed free of charge, as they might when working
20.\" professionally.
c13182ef 21.\"
fea681da
MK
22.\" Formatted or processed versions of this manual, if unaccompanied by
23.\" the source, must acknowledge the copyright and authors of this work.
24.\"
25.\" Modified Mon Apr 12 12:49:57 1993, David Metcalfe
26.\" Modified Sat Jul 24 18:56:22 1993, Rik Faith (faith@cs.unc.edu)
27.\" Modified Wed Feb 20 21:09:36 2002, Ian Redfern (redferni@logica.com)
2a8bb904 28.\" 2008-07-09, mtk, add rawmemchr()
fea681da 29.\"
781166d1 30.TH MEMCHR 3 2008-08-11 "" "Linux Programmer's Manual"
fea681da 31.SH NAME
2a8bb904 32memchr, memrchr, rawmemchr \- scan memory for a character
fea681da
MK
33.SH SYNOPSIS
34.nf
35.B #include <string.h>
2a8bb904 36
fea681da 37.BI "void *memchr(const void *" s ", int " c ", size_t " n );
2a8bb904 38
fea681da 39.BI "void *memrchr(const void *" s ", int " c ", size_t " n );
2a8bb904
MK
40
41.BI "void *rawmemchr(const void *" s ", int " c );
fea681da 42.fi
2a8bb904
MK
43.sp
44.in -4n
45Feature Test Macro Requirements for glibc (see
46.BR feature_test_macros (7)):
47.in
48.sp
49.BR rawmemchr ():
50_GNU_SOURCE
fea681da 51.SH DESCRIPTION
c13182ef 52The
63aa9df0 53.BR memchr ()
fea681da 54function scans the first \fIn\fP bytes of the memory
1c44bd5b
MK
55area pointed to by \fIs\fP for the character \fIc\fP.
56The first byte to
fea681da
MK
57match \fIc\fP (interpreted as an unsigned character) stops the operation.
58.PP
c13182ef 59The
63aa9df0 60.BR memrchr ()
c13182ef 61function is like the
63aa9df0 62.BR memchr ()
fea681da
MK
63function,
64except that it searches backwards from the end of the \fIn\fP bytes
2a8bb904
MK
65pointed to by \fIs\fP instead of forwards from the beginning.
66
67The
68.BR rawmemchr ()
69function is similar to
70.BR memchr ():
71it assumes (i.e., the programmer knows for certain)
72that the character
73.I c
74lies somewhere in the string
75.IR s ,
76and so performs an optimized search
77for the character
e346bc5a 78.IR c
2a8bb904
MK
79(i.e., no checking for the terminating null byte, or use of an argument,
80.IR n ,
81to limit the range of the search).
7ae19fdf 82If the character
2a8bb904
MK
83.I c
84is not in the string
85.IR s ,
86then
e346bc5a 87.BR rawmemchr ()
2a8bb904
MK
88may proceeed to search beyond the end of the string,
89and the result is unspecified.
90The folowing call is a fast means of locating a string's
91terminating null byte:
92.in +4n
93.nf
94
4391d173 95char *p = rawmemchr(s,\ \(aq\\0\(aq);
2a8bb904
MK
96.fi
97.in
fea681da 98.SH "RETURN VALUE"
60a90ecd
MK
99The
100.BR memchr ()
101and
102.BR memrchr ()
103functions return a pointer
fea681da
MK
104to the matching byte or NULL if the character does not occur in
105the given memory area.
2a8bb904
MK
106
107The
108.BR rawmemchr ()
109function returns a pointer to the matching byte, if one is found.
110If no matching byte is found, the result is unspecified.
781166d1
MK
111.SH VERSIONS
112.BR rawmemchr ()
113first appeared in glibc in version 2.1.
114
115.BR memrchr ()
116first appeared in glibc in version 2.2.
fea681da 117.SH "CONFORMING TO"
c13182ef 118The
63aa9df0 119.BR memchr ()
1eb85d14 120function conforms to SVr4, 4.3BSD, C89, C99, POSIX.1-2001.
2a8bb904 121
c13182ef 122The
63aa9df0 123.BR memrchr ()
fea681da 124function is a GNU extension, available since glibc 2.1.91.
2a8bb904
MK
125
126The
c7cb2bdb 127.BR rawmemchr ()
2a8bb904 128function is a GNU extension, available since glibc 2.1.
fea681da
MK
129.SH "SEE ALSO"
130.BR index (3),
131.BR rindex (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)