xref: /illumos-gate/usr/src/man/man3c/memset_s.3c (revision 2a1fd0ffe121888d44fdec321c25b53dcfaa9118)
1.\"
2.\" This file and its contents are supplied under the terms of the
3.\" Common Development and Distribution License ("CDDL"), version 1.0.
4.\" You may only use this file in accordance with the terms of version
5.\" 1.0 of the CDDL.
6.\"
7.\" A full copy of the text of the CDDL should have accompanied this
8.\" source.  A copy of the CDDL is also available via the Internet at
9.\" http://www.illumos.org/license/CDDL.
10.\"
11.\"
12.\" Copyright 2018 Nexenta Systems, Inc.
13.\"
14.Dd August 12, 2017
15.Dt MEMSET_S 3C
16.Os
17.Sh NAME
18.Nm memset_s
19.Nd copy a value to all bytes of a memory buffer
20.Sh LIBRARY
21.Lb libc
22.Sh SYNOPSIS
23.Fd #define __STDC_WANT_LIB_EXT1__ 1
24.In string.h
25.Ft errno_t
26.Fo memset_s
27.Fa "void *s"
28.Fa "rsize_t smax"
29.Fa "int c"
30.Fa "rsize_t n"
31.Fc
32.Sh DESCRIPTION
33The
34.Fn memset_s
35function copies the value of
36.Fa c
37.Po converted to an
38.Vt unsigned char
39.Pc
40into each of the first
41.Fa n
42bytes of the memory buffer pointed to by
43.Fa s .
44.Pp
45Unlike the
46.Xr memset 3C ,
47.Fn memset_s
48is guaranteed to never be optimized away by the compiler.
49.Pp
50The
51.Fn memset_s
52function detects the following runtime-constraint violations:
53.Bl -enum
54.It
55.Fa s
56is a
57.Dv NULL
58pointer.
59.It
60.Fa smax
61or
62.Fa n
63is greater than
64.Dv RSIZE_MAX .
65.It
66.Fa n
67is greater than
68.Fa smax
69.Pq buffer overflow .
70.El
71.Pp
72If runtime-constraint violation is detected, and if
73.Fa s
74and
75.Fa smax
76are valid, the
77.Fn memset_s
78function copies the value of
79.Fa c
80.Po converted to an
81.Vt unsigned char
82.Pc
83into each of the first
84.Fa smax
85bytes of the memory buffer pointed to by
86.Fa s
87before calling the runtime-constraint handler.
88.Sh RETURN VALUES
89The
90.Fn memset_s
91function returns 0 if there was no runtime-constraint violation.
92Otherwise, a non-zero value is returned.
93.Sh INTERFACE STABILITY
94.Sy Standard
95.Sh MT-LEVEL
96.Sy Safe
97.Sh SEE ALSO
98.Xr memset 3C ,
99.Xr set_constraint_handler_s 3C
100.Sh STANDARDS
101The
102.Fn memset_s
103function conforms to
104.St -isoC-2011 .
105