memccpy, memchr, memcmp, memcpy, memset, memset_s, or memmove Subroutine

Purpose

Performs memory operations and handles runtime constraint violations.

Library

Standard C Library (libc.a)

Syntax

#include <memory.h>
#include <string.h>
#define STDC_WANT_LIB_EXT1 1
void *memccpy (Target, Source, C, N)
void *Target;
const void *Source;
int C;
size_t N;

void *memchr ( S, C, N)
const void *S;
int C;
size_t N;

int memcmp (Target, Source, N)
const void *Target, *Source;
size_t N;
void *memcpy (Target, Source, N)
void *Target;
const void *Source;
size_t N;
void *memset (S, C, N)
void *S;
int C;
size_t N;
void *memmove (Target, Source,N)
void *Source;
const void *Target;
size_t N;
errno_t memset_s (s,smax,c,n)
void * s;
rsize_t smax;
int c;
rsize_t n;

Description

The memory subroutines operate on memory areas. A memory area is an array of characters bounded by a count. The memory subroutines do not check for the overflow of any receiving memory area. All of the memory subroutines are declared in the memory.h file.

The memccpy subroutine copies characters from the memory area specified by the Source parameter into the memory area specified by the Target parameter. The memccpy subroutine stops after the first character specified by the C parameter (converted to the unsigned char data type) is copied, or after N characters are copied, whichever comes first. If copying takes place between objects that overlap, the behavior is undefined.

The memcmp subroutine compares the first N characters as the unsigned chardata type in the memory area specified by the Target parameter to the first N characters as the unsigned char data type in the memory area specified by the Source parameter.

The memcpy subroutine copies N characters from the memory area specified by the Source parameter to the area specified by the Target parameter and then returns the value of the Target parameter.

The memset subroutine sets the first N characters in the memory area specified by the S parameter to the value of character C and then returns the value of the S parameter.

Like the memcpy subroutine, the memmove subroutine copies N characters from the memory area specified by the Source parameter to the area specified by the Target parameter. However, if the areas of the Source and Target parameters overlap, the move is performed non-destructively, proceeding from right to left.

The memccpy subroutine is not in the ANSI C library.

The memset_s subroutine copies the value of c (converted to an unsigned character) into each of the first n characters of the object pointed by s. Unlike memset, any call to the memset_s function is evaluated according to the rules of the abstract machine and considers that the memory indicated by s and n might be accessible in the future and contains the values indicated by c.

Runtime Constraints

  1. For the memset_s subroutine, the parameter s must not be a null pointer. Either smax or n can be greater than RSIZE_MAX, but n cannot be greater than smax.
  2. If there is a runtime constraint violation and s is not a null pointer and smax is not greater than RSIZE_MAX, the memset_s subroutine stores the value of c (converted to an unsigned character) into each of the first smax characters of the object pointed by s.

Parameters

Item Description
Target Points to the start of a memory area.  
Source Points to the start of a memory area.  
C Specifies a character to search.  
N Specifies the number of characters to search.  
S Points to the start of a memory area.  
s Specifies the destination buffer for the copy.  
c Specifies the value to be copied.  
smax Specifies the maximum number of characters that can be copied.  
n Specifies the number of characters to be copied.  

Return Values

The memccpy subroutine returns a pointer to character C after it is copied into the area specified by the Target parameter, or a null pointer if the C character is not found in the first N characters of the area specified by the Source parameter.

The memchr subroutine returns a pointer to the first occurrence of the C character in the first N characters of the memory area specified by the S parameter, or a null pointer if the C character is not found.

The memcmp subroutine returns the following values:

Item Description
Less than 0 If the value of the Target parameter is less than the values of the Source parameter.
Equal to 0 If the value of the Target parameter equals the value of the Source parameter.
Greater than 0 If the value of the Target parameter is greater than the value of the Source parameter.

The memset_s subroutine returns zero if there is no runtime constraint violation. Otherwise, a nonzero value is returned.