summaryrefslogtreecommitdiff
path: root/usr/src/man/man3c/memory.3c
blob: 368956c97fd93824fcfbb0e3138a28f07e8f8aa8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
'\" te
.\" Copyright (c) 2014, Joyent, Inc.
.\" Copyright (c) 2009, Sun Microsystems, Inc.  All Rights Reserved.
.\" Copyright 1989 AT&T
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH MEMORY 3C "Feb 4, 2009"
.SH NAME
memory, memccpy, memchr, memcmp, memcpy, memmem, memmove, memset \- memory operations
.SH SYNOPSIS
.LP
.nf
#include <string.h>

\fBvoid *\fR\fBmemccpy\fR(\fBvoid *restrict\fR \fIs1\fR, \fBconst void *restrict\fR \fIs2\fR,
     \fBint\fR \fIc\fR, \fBsize_t\fR \fIn\fR);
.fi

.LP
.nf
\fBvoid *\fR\fBmemchr\fR(\fBconst void *\fR\fIs\fR, \fBint\fR \fIc\fR, \fBsize_t\fR \fIn\fR);
.fi

.LP
.nf
\fBint\fR \fBmemcmp\fR(\fBconst void *\fR\fIs1\fR, \fBconst void *\fR\fIs2\fR, \fBsize_t\fR \fIn\fR);
.fi

.LP
.nf
\fBvoid *\fR\fBmemcpy\fR(\fBvoid *restrict\fR \fIs1\fR, \fBconst void *restrict\fR \fIs2\fR, \fBsize_t\fR \fIn\fR);
.fi

.LP
.nf
\fBvoid *\fR\fBmemmem\fR(\fBconst void *\fR\fIl\fR, \fBsize_t\fR \fIl_len\fR, \fBconst void *\fR\fIs\fR, \fBsize_t\fR \fIs_len\fR);
.fi

.LP
.nf
\fBvoid *\fR\fBmemmove\fR(\fBvoid *\fR\fIs1\fR, \fBconst void *\fR\fIs2\fR, \fBsize_t\fR \fIn\fR);
.fi

.LP
.nf
\fBvoid *\fR\fBmemset\fR(\fBvoid *\fR\fIs\fR, \fBint\fR \fIc\fR, \fBsize_t\fR \fIn\fR);
.fi

.SS "ISO C++"
.LP
.nf
#include <string.h>

\fBconst void *\fR\fBmemchr\fR(\fBconst void *\fR\fIs\fR, \fBint\fR \fIc\fR, \fBsize_t\fR \fIn\fR);
.fi

.LP
.nf
#include <cstring>

\fBvoid *std::\fR\fBmemchr\fR(\fBvoid *\fR\fIs\fR, \fBint\fR \fIc\fR, \fBsize_t\fR \fIn\fR);
.fi

.SH DESCRIPTION
.LP
These functions operate as efficiently as possible on memory areas (arrays of
bytes bounded by a count, not terminated by a null character). They do not
check for the overflow of any receiving memory area.
.sp
.LP
The \fBmemccpy()\fR function copies bytes from memory area \fIs2\fR into
\fIs1\fR, stopping after the first occurrence of \fIc\fR (converted to an
\fBunsigned char\fR) has been copied, or after \fIn\fR bytes have been copied,
whichever comes first. It returns a pointer to the byte after the copy of
\fIc\fR in \fIs1\fR, or a null pointer if \fIc\fR was not found in the first
\fIn\fR bytes of \fIs2\fR.
.sp
.LP
The \fBmemchr()\fR function returns a pointer to the first occurrence of
\fIc\fR (converted to an \fBunsigned char\fR) in the first \fIn\fR bytes (each
interpreted as an \fBunsigned char\fR) of memory area \fIs\fR, or a null
pointer if \fIc\fR does not occur.
.sp
.LP
The \fBmemcmp()\fR function compares its arguments, looking at the first
\fIn\fR bytes (each interpreted as an \fBunsigned char\fR), and returns an
integer less than, equal to, or greater than 0, according as \fIs1\fR is
lexicographically less than, equal to, or greater than \fIs2\fR when taken to
be unsigned characters.
.sp
.LP
The \fBmemcpy()\fR function copies \fIn\fR bytes from memory area \fIs2\fR to
\fIs1\fR. It returns \fIs1\fR. If copying takes place between objects that
overlap, the behavior is undefined.
.sp
.LP
The \fBmemmem()\fR function searches for the \fIs_len\fR long byte pattern
\fIs\fR in the memory region starting at \fIl\fR for \fIl_len\fR bytes. If a
match is found, a pointer to the starting location in \fIl\fR is returned. If no
match is found, \fIl_len\fR is zero, \fIs_len\fR is zero, or \fIl_len\fR is less
than \fIs_len\fR, then a null pointer is return.
.sp
.LP
The \fBmemmove()\fR function copies \fIn\fR bytes from memory area \fIs2\fR to
memory area \fIs1\fR. Copying between objects that overlap will take place
correctly. It returns \fIs1\fR.
.sp
.LP
The \fBmemset()\fR function sets the first \fIn\fR bytes in memory area \fIs\fR
to the value of \fIc\fR (converted to an \fBunsigned char\fR). It returns
\fIs\fR.
.SH USAGE
.LP
Using \fBmemcpy()\fR might be faster than using \fBmemmove()\fR if the
application knows that the objects being copied do not overlap.
.SH ATTRIBUTES
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	Stable
_
MT-Level	MT-Safe
_
Standard	See \fBstandards\fR(5).
.TE

.SH SEE ALSO
.LP
\fBstring\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)
.SH NOTES
.LP
Overlap between objects being copied can arise even when their (virtual)
address ranges appear to be disjoint; for example, as a result of
memory-mapping overlapping portions of the same underlying file, or of
attaching the same shared memory segment more than once.