1/* $NetBSD: strings.h,v 1.3 2008/04/28 20:22:54 martin Exp $ */
2
3/*-
4 *
5 * SPDX-License-Identifier: BSD-2-Clause
6 *
7 * Copyright (c) 2007 The NetBSD Foundation, Inc.
8 * All rights reserved.
9 *
10 * This code is derived from software contributed to The NetBSD Foundation
11 * by Christos Zoulas.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35// zig patch: ssp/strings.h header was added in FreeBSD 15
36#if __FreeBSD_version < 1500500
37 #error "ssp/strings.h did not exist before FreeBSD 15"
38#endif /* error for FreeBSD before 15 */
39
40#ifndef _SSP_STRINGS_H_
41#define _SSP_STRINGS_H_
42
43#include <ssp/ssp.h>
44#include <string.h>
45
46#if __SSP_FORTIFY_LEVEL > 0
47
48#define _ssp_bcopy(srcvar, src, dstvar, dst, lenvar, len) __extension__ ({ \
49 const void *srcvar = (src); \
50 void *dstvar = (dst); \
51 size_t lenvar = (len); \
52 ((__ssp_bos0(dstvar) != (size_t)-1) ? \
53 __builtin___memmove_chk(dstvar, srcvar, lenvar, \
54 __ssp_bos0(dstvar)) : \
55 __memmove_ichk(dstvar, srcvar, lenvar)); \
56})
57
58#define bcopy(src, dst, len) \
59 _ssp_bcopy(__ssp_var(srcv), src, __ssp_var(dstv), dst, __ssp_var(lenv), len)
60
61#define _ssp_bzero(dstvar, dst, lenvar, len) __extension__ ({ \
62 void *dstvar = (dst); \
63 size_t lenvar = (len); \
64 ((__ssp_bos0(dstvar) != (size_t)-1) ? \
65 __builtin___memset_chk(dstvar, 0, lenvar, \
66 __ssp_bos0(dstvar)) : \
67 __memset_ichk(dstvar, 0, lenvar)); \
68})
69
70#define bzero(dst, len) _ssp_bzero(__ssp_var(dstv), dst, __ssp_var(lenv), len)
71
72__BEGIN_DECLS
73__ssp_redirect(void, explicit_bzero, (void *__buf, size_t __len),
74 (__buf, __len));
75__END_DECLS
76
77#endif /* __SSP_FORTIFY_LEVEL > 0 */
78#endif /* _SSP_STRINGS_H_ */