MEMORY(3) BSD MEMORY(3)
NAME
memory: memchr, memcmp, memcpy, memmove, memset - memory operations
SYNOPSIS
#include <string.h>
void *memchr (s, c, n)
const void *s;
int c;
size_t n;
int memcmp (s1, s2, n)
const void *s1, *s2;
size_t n;
void *memcpy (s1, s2, n)
void *s1;
const void *s2;
size_t n;
void *memmove (s1, s2, n)
void *s1;
const void *s2;
size_t n;
void *memset (s, c, n)
void *s;
int c;
size_t n;
DESCRIPTION
These functions operate as efficiently as possible on memory areas
(arrays of characters bounded by a count, not terminated by a null
character). They do not check for the overflow of any receiving memory
area.
memchr returns a pointer to the first occurrence of character c in the
first n characters of memory area s, or a NULL pointer if c does not
occur.
memcmp compares its arguments, looking at the first n characters only,
and returns an integer less than, equal to, or greater than 0, according
as s1 is lexicographically less than, equal to, or greater than s2.
memcpy copies n characters from memory area s2 to s1. It returns s1.
memmove copies n characters from the object pointed to by s2 into the
object pointed to by s1. Copying takes place as if the n characters from
the object pointed to by s2 are first copied into a temporary array of n
characters that does not overlap the objects pointed to by s1 and s2, and
then the n characters from the temporary array are copied into the object
pointed to by s1. memmove returns the value of s1.
memset sets the first n characters in memory area s to the value of
character c. It returns s.
SEE ALSO
cc(1).
NOTES
To be compatible with common C usage, make memchr, memcpy, and memset
return type pointer-to-character by compiling your program with the
-A nansi
option (see cc(1)) and inserting the directive
#define _CLASSIC_TYPES
before any #include directives.
CAVEATS
memcmp is implemented by using the most natural character comparison on
the machine. Thus the sign of the value returned when one of the
characters has its high order bit set is not the same in all
implementations and should not be relied upon.
Character movement is performed differently in different implementations.
Thus overlapping moves may yield surprises.