blob: 00d470452c5ba3fcd60f0de1fa454a19317124a7 [file] [log] [blame]
Andrew Scull2b5fbad2019-04-05 13:55:56 +01001/*
2 * Copyright 2019 The Hafnium Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "hf/std.h"
18
19#include "hf/panic.h"
20
21/* Declare unsafe functions locally so they are not available globally. */
22void *memset(void *s, int c, size_t n);
23
24void memset_s(void *dest, rsize_t destsz, int ch, rsize_t count)
25{
26 if (dest == NULL) {
27 goto fail;
28 }
29
30 if (destsz > RSIZE_MAX || count > RSIZE_MAX) {
31 goto fail;
32 }
33
34 if (count > destsz) {
35 goto fail;
36 }
37
38 memset(dest, ch, count);
39 return;
40
41fail:
42 panic("memset_s failure");
43}