memset_s
—
copy a value to all bytes of a memory buffer
Standard C Library (libc, -lc)
#define __STDC_WANT_LIB_EXT1__ 1
#include
<string.h>
errno_t
memset_s
(
void
*s,
rsize_t smax,
int c,
rsize_t
n);
The
memset_s
() function copies the value of
c (converted to an
unsigned char) into each of the first
n bytes of the memory buffer pointed to by
s.
Unlike the
memset(3C),
memset_s
() is guaranteed to never be
optimized away by the compiler.
The
memset_s
() function detects the following
runtime-constraint violations:
- s is a
NULL
pointer.
- smax or
n is greater than
RSIZE_MAX
.
- n is greater than
smax (buffer overflow).
If runtime-constraint violation is detected, and if
s and
smax
are valid, the
memset_s
() function copies
the value of
c (converted to an
unsigned char) into each of the first
smax bytes of the memory buffer pointed to by
s before calling the runtime-constraint
handler.
The
memset_s
() function returns 0 if there
was no runtime-constraint violation. Otherwise, a non-zero value is returned.
Standard
Safe
memset(3C),
set_constraint_handler(3C)
The
memset_s
() function conforms to
ISO/IEC 9899:2011
(“ISO C11”).