]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/memchr.3
memchr.3: Remove mention of terminating null in description of rawmemchr()
[thirdparty/man-pages.git] / man3 / memchr.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\" and Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
3 .\" <mtk.manpages@gmail.com>
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.
13 .\"
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.
21 .\"
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)
28 .\" 2008-07-09, mtk, add rawmemchr()
29 .\"
30 .TH MEMCHR 3 2012-04-16 "" "Linux Programmer's Manual"
31 .SH NAME
32 memchr, memrchr, rawmemchr \- scan memory for a character
33 .SH SYNOPSIS
34 .nf
35 .B #include <string.h>
36
37 .BI "void *memchr(const void *" s ", int " c ", size_t " n );
38
39 .BI "void *memrchr(const void *" s ", int " c ", size_t " n );
40
41 .BI "void *rawmemchr(const void *" s ", int " c );
42 .fi
43 .sp
44 .in -4n
45 Feature Test Macro Requirements for glibc (see
46 .BR feature_test_macros (7)):
47 .in
48 .sp
49 .BR memrchr (),
50 .BR rawmemchr ():
51 _GNU_SOURCE
52 .SH DESCRIPTION
53 The
54 .BR memchr ()
55 function scans the first \fIn\fP bytes of the memory
56 area pointed to by \fIs\fP for the character \fIc\fP.
57 The first byte to
58 match \fIc\fP (interpreted as an unsigned character) stops the operation.
59 .PP
60 The
61 .BR memrchr ()
62 function is like the
63 .BR memchr ()
64 function,
65 except that it searches backward from the end of the \fIn\fP bytes
66 pointed to by \fIs\fP instead of forward from the beginning.
67
68 The
69 .BR rawmemchr ()
70 function is similar to
71 .BR memchr ():
72 it assumes (i.e., the programmer knows for certain)
73 that the character
74 .I c
75 lies somewhere in the string
76 .IR s ,
77 and so performs an optimized search
78 for the character
79 .IR c
80 (i.e., no use of a count argument argument to limit the range of the search).
81 If the character
82 .I c
83 is not in the string
84 .IR s ,
85 then
86 .BR rawmemchr ()
87 may proceed to search beyond the end of the string,
88 and the result is unspecified.
89 The following call is a fast means of locating a string's
90 terminating null byte:
91 .in +4n
92 .nf
93
94 char *p = rawmemchr(s,\ \(aq\\0\(aq);
95 .fi
96 .in
97 .SH "RETURN VALUE"
98 The
99 .BR memchr ()
100 and
101 .BR memrchr ()
102 functions return a pointer
103 to the matching byte or NULL if the character does not occur in
104 the given memory area.
105
106 The
107 .BR rawmemchr ()
108 function returns a pointer to the matching byte, if one is found.
109 If no matching byte is found, the result is unspecified.
110 .SH VERSIONS
111 .BR rawmemchr ()
112 first appeared in glibc in version 2.1.
113
114 .BR memrchr ()
115 first appeared in glibc in version 2.2.
116 .SH "CONFORMING TO"
117 The
118 .BR memchr ()
119 function conforms to SVr4, 4.3BSD, C89, C99, POSIX.1-2001.
120
121 The
122 .BR memrchr ()
123 function is a GNU extension, available since glibc 2.1.91.
124
125 The
126 .BR rawmemchr ()
127 function is a GNU extension, available since glibc 2.1.
128 .SH "SEE ALSO"
129 .BR ffs (3),
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)