safec  3.0
Safe C Library - ISO TR24731 Bounds Checking Interface
memccpy_s.c File Reference
#include "safe_mem_lib.h"
+ Include dependency graph for memccpy_s.c:

Functions

EXPORT errno_t memccpy_s (void *restrict dest, rsize_t dmax, const void *restrict src, int c, rsize_t n)
 memccpy_s copies no more than n bytes from memory area src to memory area dest, stopping when the character c is found. More...
 

Function Documentation

◆ memccpy_s()

EXPORT errno_t memccpy_s ( void *restrict  dest,
rsize_t  dmax,
const void *restrict  src,
int  c,
rsize_t  n 
)

memccpy_s copies no more than n bytes from memory area src to memory area dest, stopping when the character c is found.

Throws error if the memory areas overlap. With SAFECLIB_STR_NULL_SLACK defined the rest (max. n bytes, not dmax) is cleared with NULL bytes.

Parameters
[out]destpointer to the memory that will be replaced by src.
[in]dmaxmaximum length of the resulting dest, in bytes
[in]srcpointer to the memory that will be copied to dest
[in]ccharacter to be found
[in]nmaximum number bytes of src that can be copied
Precondition
Neither dest nor src shall be a null pointer.
dmax shall not be 0.
dmax shall not be greater than RSIZE_MAX_MEM.
n shall not be greater than dmax.
Copying shall not take place between regions that overlap.
Note
from FreeBSD
Returns
The memccpy() function returns a pointer to the next character in dest after c, or NULL if c was not found in the first n characters of src. If there is a runtime-constraint violation, the memccpy_s function stores zeros in the first dmax bytes of the region pointed to by dest if dest is not a null pointer and n is valid.
Return values
EOKwhen operation is successful
ESNULLPwhen dest/src is NULL POINTER
ESZEROLwhen dmax = ZERO. Before C11 also with n = ZERO
ESLEMAXwhen dmax/n > RSIZE_MAX_MEM
ESNOSPCwhen dmax < n
ESOVRLPwhen src memory overlaps dst
See also
memcpy_s(), strncpy_s()