'\" te .\" Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. .\" Copyright 1989 AT&T .TH memory 3C "11 Oct 2010" "SunOS 5.11" "Standard C Library Functions" .SH NAME memory, memccpy, memchr, memcmp, memcpy, memmove, memset, memmem \- memory operations .SH SYNOPSIS .LP .nf #include \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\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 .LP .nf void *memmem(const void *\fIhaystack\fR, size_t \fIhaystacklen\fR, const void *\fIneedle\fR, size_t \fIneedlelen\fR); .fi .SS "ISO C++" .LP .nf #include \fBconst void *\fR\fBmemchr\fR(\fBconst void *\fR\fIs\fR, \fBint\fR \fIc\fR, \fBsize_t\fR \fIn\fR); .fi .LP .nf #include \fBvoid *std::\fR\fBmemchr\fR(\fBvoid *\fR\fIs\fR, \fBint\fR \fIc\fR, \fBsize_t\fR \fIn\fR); .fi .SH DESCRIPTION .sp .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 \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. .sp .LP The \fBmemmem()\fR function locates the start of the first occurrence of the substring \fIneedle\fR of length \fIneedlelen\fR in the memory area \fIhaystack\fR of length \fIhaystacklen\fR. It returns a pointer to the start of the substring, or \fINULL\fR if the substring is not found. .SH USAGE .sp .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 .sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPEATTRIBUTE VALUE _ Interface StabilityCommitted _ MT-LevelMT-Safe _ StandardSee \fBstandards\fR(5). .TE .SH SEE ALSO .sp .LP \fBstring\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5) .SH NOTES .sp .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.