]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/memchr.3
Many pages: Use correct letter case in page titles (TH)
[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 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
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)
10 .\" 2008-07-09, mtk, add rawmemchr()
11 .\"
12 .TH memchr 3 (date) "Linux man-pages (unreleased)"
13 .SH NAME
14 memchr, memrchr, rawmemchr \- scan memory for a character
15 .SH LIBRARY
16 Standard C library
17 .RI ( libc ", " \-lc )
18 .SH SYNOPSIS
19 .nf
20 .B #include <string.h>
21 .PP
22 .BI "void *memchr(const void *" s ", int " c ", size_t " n );
23 .BI "void *memrchr(const void *" s ", int " c ", size_t " n );
24 .BI "void *rawmemchr(const void *" s ", int " c );
25 .fi
26 .PP
27 .RS -4
28 Feature Test Macro Requirements for glibc (see
29 .BR feature_test_macros (7)):
30 .RE
31 .PP
32 .BR memrchr (),
33 .BR rawmemchr ():
34 .nf
35 _GNU_SOURCE
36 .fi
37 .SH DESCRIPTION
38 The
39 .BR memchr ()
40 function scans the initial
41 .I n
42 bytes of the memory
43 area pointed to by
44 .I s
45 for the first instance of
46 .IR c .
47 Both
48 .I c
49 and the bytes of the memory area pointed to by
50 .I s
51 are interpreted as
52 .IR "unsigned char" .
53 .PP
54 The
55 .BR memrchr ()
56 function is like the
57 .BR memchr ()
58 function,
59 except that it searches backward from the end of the
60 .I n
61 bytes pointed to by
62 .I s
63 instead of forward from the beginning.
64 .PP
65 The
66 .BR rawmemchr ()
67 function is similar to
68 .BR memchr ():
69 it assumes (i.e., the programmer knows for certain)
70 that an instance of
71 .I c
72 lies somewhere in the memory area starting at the location pointed to by
73 .IR s ,
74 and so performs an optimized search for
75 .I c
76 (i.e., no use of a count argument to limit the range of the search).
77 If an instance of
78 .I c
79 is not found, the results are unpredictable.
80 The following call is a fast means of locating a string's
81 terminating null byte:
82 .PP
83 .in +4n
84 .EX
85 char *p = rawmemchr(s,\ \(aq\e0\(aq);
86 .EE
87 .in
88 .SH RETURN VALUE
89 The
90 .BR memchr ()
91 and
92 .BR memrchr ()
93 functions return a pointer
94 to the matching byte or NULL if the character does not occur in
95 the given memory area.
96 .PP
97 The
98 .BR rawmemchr ()
99 function returns a pointer to the matching byte, if one is found.
100 If no matching byte is found, the result is unspecified.
101 .SH VERSIONS
102 .BR rawmemchr ()
103 first appeared in glibc in version 2.1.
104 .PP
105 .BR memrchr ()
106 first appeared in glibc in version 2.2.
107 .SH ATTRIBUTES
108 For an explanation of the terms used in this section, see
109 .BR attributes (7).
110 .ad l
111 .nh
112 .TS
113 allbox;
114 lbx lb lb
115 l l l.
116 Interface Attribute Value
117 T{
118 .BR memchr (),
119 .BR memrchr (),
120 .BR rawmemchr ()
121 T} Thread safety MT-Safe
122 .TE
123 .hy
124 .ad
125 .sp 1
126 .SH STANDARDS
127 .BR memchr ():
128 POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.
129 .PP
130 The
131 .BR memrchr ()
132 function is a GNU extension, available since glibc 2.1.91.
133 .PP
134 The
135 .BR rawmemchr ()
136 function is a GNU extension, available since glibc 2.1.
137 .SH SEE ALSO
138 .BR bstring (3),
139 .BR ffs (3),
140 .BR index (3),
141 .BR memmem (3),
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)