]>
Commit | Line | Data |
---|---|---|
a1eaacb1 | 1 | '\" t |
fea681da | 2 | .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) |
2a8bb904 MK |
3 | .\" and Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk |
4 | .\" <mtk.manpages@gmail.com> | |
fea681da | 5 | .\" |
5fbde956 | 6 | .\" SPDX-License-Identifier: Linux-man-pages-copyleft |
fea681da MK |
7 | .\" |
8 | .\" Modified Mon Apr 12 12:49:57 1993, David Metcalfe | |
9 | .\" Modified Sat Jul 24 18:56:22 1993, Rik Faith (faith@cs.unc.edu) | |
10 | .\" Modified Wed Feb 20 21:09:36 2002, Ian Redfern (redferni@logica.com) | |
2a8bb904 | 11 | .\" 2008-07-09, mtk, add rawmemchr() |
fea681da | 12 | .\" |
4c1c5274 | 13 | .TH memchr 3 (date) "Linux man-pages (unreleased)" |
fea681da | 14 | .SH NAME |
2a8bb904 | 15 | memchr, memrchr, rawmemchr \- scan memory for a character |
0a2adce0 AC |
16 | .SH LIBRARY |
17 | Standard C library | |
8fc3b2cf | 18 | .RI ( libc ", " \-lc ) |
fea681da MK |
19 | .SH SYNOPSIS |
20 | .nf | |
21 | .B #include <string.h> | |
dbfe9c70 | 22 | .PP |
c64cd13e AC |
23 | .BI "void *memchr(const void " s [. n "], int " c ", size_t " n ); |
24 | .BI "void *memrchr(const void " s [. n "], int " c ", size_t " n ); | |
b2af20ea | 25 | .PP |
afb2a42b | 26 | .BI "[[deprecated]] void *rawmemchr(const void *" s ", int " c ); |
fea681da | 27 | .fi |
68e4db0a | 28 | .PP |
d39ad78f | 29 | .RS -4 |
2a8bb904 MK |
30 | Feature Test Macro Requirements for glibc (see |
31 | .BR feature_test_macros (7)): | |
d39ad78f | 32 | .RE |
68e4db0a | 33 | .PP |
13a7959b | 34 | .BR memrchr (), |
2a8bb904 | 35 | .BR rawmemchr (): |
1dd0d7b4 MK |
36 | .nf |
37 | _GNU_SOURCE | |
38 | .fi | |
fea681da | 39 | .SH DESCRIPTION |
c13182ef | 40 | The |
63aa9df0 | 41 | .BR memchr () |
9640b1b3 MK |
42 | function scans the initial |
43 | .I n | |
44 | bytes of the memory | |
45 | area pointed to by | |
46 | .I s | |
47 | for the first instance of | |
48 | .IR c . | |
49 | Both | |
50 | .I c | |
51 | and the bytes of the memory area pointed to by | |
52 | .I s | |
53 | are interpreted as | |
54 | .IR "unsigned char" . | |
fea681da | 55 | .PP |
c13182ef | 56 | The |
63aa9df0 | 57 | .BR memrchr () |
c13182ef | 58 | function is like the |
63aa9df0 | 59 | .BR memchr () |
fea681da | 60 | function, |
9640b1b3 MK |
61 | except that it searches backward from the end of the |
62 | .I n | |
63 | bytes pointed to by | |
64 | .I s | |
65 | instead of forward from the beginning. | |
847e0d88 | 66 | .PP |
2a8bb904 MK |
67 | The |
68 | .BR rawmemchr () | |
69 | function is similar to | |
b2af20ea AC |
70 | .BR memchr (), |
71 | but it assumes | |
72 | (i.e., the programmer knows for certain) | |
9640b1b3 | 73 | that an instance of |
2a8bb904 | 74 | .I c |
9640b1b3 | 75 | lies somewhere in the memory area starting at the location pointed to by |
b2af20ea | 76 | .IR s . |
9640b1b3 | 77 | If an instance of |
2a8bb904 | 78 | .I c |
b2af20ea AC |
79 | is not found, the behavior is undefined. |
80 | Use either | |
81 | .BR strlen (3) | |
82 | or | |
83 | .BR memchr (3) | |
84 | instead. | |
47297adb | 85 | .SH RETURN VALUE |
60a90ecd MK |
86 | The |
87 | .BR memchr () | |
88 | and | |
89 | .BR memrchr () | |
90 | functions return a pointer | |
fea681da MK |
91 | to the matching byte or NULL if the character does not occur in |
92 | the given memory area. | |
847e0d88 | 93 | .PP |
2a8bb904 MK |
94 | The |
95 | .BR rawmemchr () | |
94877d15 | 96 | function returns a pointer to the matching byte. |
daecb330 | 97 | .SH ATTRIBUTES |
f92bb4d8 PH |
98 | For an explanation of the terms used in this section, see |
99 | .BR attributes (7). | |
c466875e MK |
100 | .ad l |
101 | .nh | |
f92bb4d8 PH |
102 | .TS |
103 | allbox; | |
c466875e | 104 | lbx lb lb |
f92bb4d8 PH |
105 | l l l. |
106 | Interface Attribute Value | |
107 | T{ | |
daecb330 PH |
108 | .BR memchr (), |
109 | .BR memrchr (), | |
daecb330 | 110 | .BR rawmemchr () |
f92bb4d8 PH |
111 | T} Thread safety MT-Safe |
112 | .TE | |
c466875e MK |
113 | .hy |
114 | .ad | |
115 | .sp 1 | |
3113c7f3 | 116 | .SH STANDARDS |
4131356c AC |
117 | .TP |
118 | .BR memchr () | |
119 | C11, POSIX.1-2008. | |
120 | .TP | |
63aa9df0 | 121 | .BR memrchr () |
4131356c AC |
122 | .TQ |
123 | .BR rawmemchr () | |
124 | GNU. | |
125 | .SH HISTORY | |
126 | .TP | |
127 | .BR memchr () | |
128 | POSIX.1-2001, C89, SVr4, 4.3BSD. | |
129 | .TP | |
130 | .BR memrchr () | |
131 | glibc 2.2. | |
132 | .TP | |
c7cb2bdb | 133 | .BR rawmemchr () |
4131356c | 134 | glibc 2.1. |
47297adb | 135 | .SH SEE ALSO |
879091c9 | 136 | .BR bstring (3), |
52aa4b97 | 137 | .BR ffs (3), |
3924b70d | 138 | .BR memmem (3), |
fea681da MK |
139 | .BR strchr (3), |
140 | .BR strpbrk (3), | |
141 | .BR strrchr (3), | |
142 | .BR strsep (3), | |
143 | .BR strspn (3), | |
144 | .BR strstr (3), | |
145 | .BR wmemchr (3) |