]> git.saurik.com Git - apple/libc.git/blame - string/NetBSD/memset_s.3
Libc-1244.1.7.tar.gz
[apple/libc.git] / string / NetBSD / memset_s.3
CommitLineData
6465356a
A
1.\"
2.\" Copyright (c) 2012 The NetBSD Foundation, Inc.
3.\" All rights reserved.
4.\"
5.\" This code is derived from software contributed to The NetBSD Foundation
6.\" by Alan Barrett
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution.
16.\"
17.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27.\" POSSIBILITY OF SUCH DAMAGE.
28.\"
29.\" $NetBSD$
30.\"
31.Dd February 21, 2012
32.Dt MEMSET_S 3
33.Os
34.Sh NAME
35.Nm memset_s
36.Nd copy a value to all bytes of a memory buffer
37.Sh LIBRARY
38.Lb libc
39.Sh SYNOPSIS
40.Fd "#define __STDC_WANT_LIB_EXT1__ 1
41.In string.h
42.Ft errno_t
43.Fn memset_s "void *s" "rsize_t smax" "int c" "rsize_t n"
44.Sh DESCRIPTION
45The
46.Fn memset_s
47function copies the value
48.Fa c
49(converted to an unsigned char)
50into each of the first
51.Fa n
52bytes of the memory buffer whose starting address is given by
53.Fa s .
54.Pp
b061a43b 55It is a runtime-constraints violation if
6465356a
A
56.Fa s
57is a null pointer,
58or if either of
59.Fa smax
60or
61.Fa n
62is larger than
63.Dv RSIZE_MAX ,
64or if
65.Fa smax
66is smaller than
67.Fa n .
68If there is a runtime-constraints violation, and if
69.Fa s
70is not a null pointer,
71and if
72.Fa smax
73is not larger than
74.Dv RSIZE_MAX ,
75then, before reporting the runtime-constraints violation,
76.Fn memset_s
77copies
78.Fa smax
79bytes to the destination.
80.Pp
81In contrast to the
82.Xr memset 3
83function,
84calls to
85.Fn memset_s
86will never be
87.Dq optimised away
88by a compiler.
89This property is required by the following sentences in
90section K.3.7.4.1 of
91.St -isoC-2011 :
92.Bd -filled -offset indent
93Unlike
94.Fn memset ,
95any call to the
96.Fn memset_s
97function shall be evaluated strictly according to the rules of
98the abstract machine as described in (5.1.2.3).
99That is, any call to the
100.Fn memset_s
101function shall assume that the memory indicated by
102.Fa s
103and
104.Fa n
105may be accessible in the future and thus must contain
106the values indicated by
107.Fa c .
108.Ed
109.Sh RETURN VALUES
110The
111.Fn memset_s
112function returns zero for success, or a non-zero error code
113if there was a runtime-constraints violation.
114.Sh ERRORS
115.Fn memset_s
116returns the following error codes.
117It does not store the error code in the global
118.Va errno
119variable:
120.Bl -tag -width Er
121.It Bq Er EINVAL
122The
123.Fa s
124argument was a null pointer.
125.It Bq Er E2BIG
126One or both of
127.Fa smax
128or
129.Fa n
130was larger than
131.Dv RSIZE_MAX .
132.It Bq Er EOVERFLOW
133.Fa n
134was larger than
135.Fa smax .
136.El
137.
138.Sh SEE ALSO
139.Xr memset 3 .
140.Sh STANDARDS
141The
142.Fn memset_s
143function conforms to
144.St -isoC-2011 ,
145except that the
146.Fn set_constraint_handler_s
147interface is not supported.