OSDN Git Service

LDP: Update original to LDP v3.68
[linuxjm/LDP_man-pages.git] / original / 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 .\" %%%LICENSE_START(VERBATIM)
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.
14 .\"
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.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" %%%LICENSE_END
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)
30 .\" 2008-07-09, mtk, add rawmemchr()
31 .\"
32 .TH MEMCHR 3  2014-03-10 "" "Linux Programmer's Manual"
33 .SH NAME
34 memchr, memrchr, rawmemchr \- scan memory for a character
35 .SH SYNOPSIS
36 .nf
37 .B #include <string.h>
38
39 .BI "void *memchr(const void *" s ", int " c ", size_t " n );
40
41 .BI "void *memrchr(const void *" s ", int " c ", size_t " n );
42
43 .BI "void *rawmemchr(const void *" s ", int " c );
44 .fi
45 .sp
46 .in -4n
47 Feature Test Macro Requirements for glibc (see
48 .BR feature_test_macros (7)):
49 .in
50 .sp
51 .BR memrchr (),
52 .BR rawmemchr ():
53 _GNU_SOURCE
54 .SH DESCRIPTION
55 The
56 .BR memchr ()
57 function scans the initial
58 .I n
59 bytes of the memory
60 area pointed to by
61 .I s
62 for the first instance of
63 .IR c .
64 Both
65 .I c
66 and the bytes of the memory area pointed to by
67 .I s
68 are interpreted as
69 .IR "unsigned char" .
70 .PP
71 The
72 .BR memrchr ()
73 function is like the
74 .BR memchr ()
75 function,
76 except that it searches backward from the end of the
77 .I n
78 bytes pointed to by
79 .I s
80 instead of forward from the beginning.
81
82 The
83 .BR rawmemchr ()
84 function is similar to
85 .BR memchr ():
86 it assumes (i.e., the programmer knows for certain)
87 that an instance of
88 .I c
89 lies somewhere in the memory area starting at the location pointed to by
90 .IR s ,
91 and so performs an optimized search for
92 .IR c
93 (i.e., no use of a count argument to limit the range of the search).
94 If an instance of
95 .I c
96 is not found, the results are unpredictable.
97 The following call is a fast means of locating a string's
98 terminating null byte:
99 .in +4n
100 .nf
101
102 char *p = rawmemchr(s,\ \(aq\\0\(aq);
103 .fi
104 .in
105 .SH RETURN VALUE
106 The
107 .BR memchr ()
108 and
109 .BR memrchr ()
110 functions return a pointer
111 to the matching byte or NULL if the character does not occur in
112 the given memory area.
113
114 The
115 .BR rawmemchr ()
116 function returns a pointer to the matching byte, if one is found.
117 If no matching byte is found, the result is unspecified.
118 .SH VERSIONS
119 .BR rawmemchr ()
120 first appeared in glibc in version 2.1.
121
122 .BR memrchr ()
123 first appeared in glibc in version 2.2.
124 .SH ATTRIBUTES
125 .SS Multithreading (see pthreads(7))
126 The
127 .BR memchr (),
128 .BR memrchr (),
129 and
130 .BR rawmemchr ()
131 functions are thread-safe.
132 .SH CONFORMING TO
133 The
134 .BR memchr ()
135 function conforms to SVr4, 4.3BSD, C89, C99, POSIX.1-2001.
136
137 The
138 .BR memrchr ()
139 function is a GNU extension, available since glibc 2.1.91.
140
141 The
142 .BR rawmemchr ()
143 function is a GNU extension, available since glibc 2.1.
144 .SH SEE ALSO
145 .BR ffs (3),
146 .BR index (3),
147 .BR rindex (3),
148 .BR strchr (3),
149 .BR strpbrk (3),
150 .BR strrchr (3),
151 .BR strsep (3),
152 .BR strspn (3),
153 .BR strstr (3),
154 .BR wmemchr (3)
155 .SH COLOPHON
156 This page is part of release 3.68 of the Linux
157 .I man-pages
158 project.
159 A description of the project,
160 information about reporting bugs,
161 and the latest version of this page,
162 can be found at
163 \%http://www.kernel.org/doc/man\-pages/.