]> git.ipfire.org Git - thirdparty/glibc.git/blame - string/bits/string_fortified.h
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / string / bits / string_fortified.h
CommitLineData
2b778ceb 1/* Copyright (C) 2004-2021 Free Software Foundation, Inc.
b5cc329c
UD
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
59ba27a6 15 License along with the GNU C Library; if not, see
5a82c748 16 <https://www.gnu.org/licenses/>. */
b5cc329c 17
09a596cc
ZW
18#ifndef _BITS_STRING_FORTIFIED_H
19#define _BITS_STRING_FORTIFIED_H 1
20
b5cc329c 21#ifndef _STRING_H
09a596cc 22# error "Never use <bits/string_fortified.h> directly; include <string.h> instead."
b5cc329c
UD
23#endif
24
5ac3ea17 25__fortify_function void *
a784e502 26__NTH (memcpy (void *__restrict __dest, const void *__restrict __src,
de1c3ebb
UD
27 size_t __len))
28{
2a3224c5
SP
29 return __builtin___memcpy_chk (__dest, __src, __len,
30 __glibc_objsize0 (__dest));
de1c3ebb 31}
b5cc329c 32
5ac3ea17 33__fortify_function void *
a784e502 34__NTH (memmove (void *__dest, const void *__src, size_t __len))
de1c3ebb 35{
2a3224c5
SP
36 return __builtin___memmove_chk (__dest, __src, __len,
37 __glibc_objsize0 (__dest));
de1c3ebb 38}
b5cc329c
UD
39
40#ifdef __USE_GNU
5ac3ea17 41__fortify_function void *
a784e502 42__NTH (mempcpy (void *__restrict __dest, const void *__restrict __src,
de1c3ebb
UD
43 size_t __len))
44{
2a3224c5
SP
45 return __builtin___mempcpy_chk (__dest, __src, __len,
46 __glibc_objsize0 (__dest));
de1c3ebb 47}
b5cc329c
UD
48#endif
49
50
553cc5f9
UD
51/* The first two tests here help to catch a somewhat common problem
52 where the second and third parameter are transposed. This is
53 especially problematic if the intended fill value is zero. In this
54 case no work is done at all. We detect these problems by referring
55 non-existing functions. */
5ac3ea17 56__fortify_function void *
de1c3ebb
UD
57__NTH (memset (void *__dest, int __ch, size_t __len))
58{
2a3224c5
SP
59 return __builtin___memset_chk (__dest, __ch, __len,
60 __glibc_objsize0 (__dest));
de1c3ebb 61}
b5cc329c 62
498afc54 63#ifdef __USE_MISC
38765ab6 64# include <bits/strings_fortified.h>
75dafa2f
AZ
65
66void __explicit_bzero_chk (void *__dest, size_t __len, size_t __destlen)
06febd8c 67 __THROW __nonnull ((1)) __attr_access ((__write_only__, 1, 2));
75dafa2f
AZ
68
69__fortify_function void
70__NTH (explicit_bzero (void *__dest, size_t __len))
71{
2a3224c5 72 __explicit_bzero_chk (__dest, __len, __glibc_objsize0 (__dest));
75dafa2f 73}
b5cc329c
UD
74#endif
75
5ac3ea17 76__fortify_function char *
a784e502 77__NTH (strcpy (char *__restrict __dest, const char *__restrict __src))
de1c3ebb 78{
2a3224c5 79 return __builtin___strcpy_chk (__dest, __src, __glibc_objsize (__dest));
de1c3ebb 80}
b5cc329c
UD
81
82#ifdef __USE_GNU
5ac3ea17 83__fortify_function char *
a784e502 84__NTH (stpcpy (char *__restrict __dest, const char *__restrict __src))
de1c3ebb 85{
2a3224c5 86 return __builtin___stpcpy_chk (__dest, __src, __glibc_objsize (__dest));
de1c3ebb 87}
b5cc329c
UD
88#endif
89
90
5ac3ea17 91__fortify_function char *
a784e502 92__NTH (strncpy (char *__restrict __dest, const char *__restrict __src,
de1c3ebb
UD
93 size_t __len))
94{
2a3224c5
SP
95 return __builtin___strncpy_chk (__dest, __src, __len,
96 __glibc_objsize (__dest));
de1c3ebb 97}
b5cc329c 98
7163ace3
SP
99#if __GNUC_PREREQ (4, 7) || __glibc_clang_prereq (2, 6)
100__fortify_function char *
101__NTH (stpncpy (char *__dest, const char *__src, size_t __n))
102{
2a3224c5
SP
103 return __builtin___stpncpy_chk (__dest, __src, __n,
104 __glibc_objsize (__dest));
7163ace3
SP
105}
106#else
a784e502 107extern char *__stpncpy_chk (char *__dest, const char *__src, size_t __n,
06febd8c
MS
108 size_t __destlen) __THROW
109 __attr_access ((__write_only__, 1, 3)) __attr_access ((__read_only__, 2));
a784e502 110extern char *__REDIRECT_NTH (__stpncpy_alias, (char *__dest, const char *__src,
dc4bb1c2 111 size_t __n), stpncpy);
8215c9ec 112
5ac3ea17 113__fortify_function char *
a784e502 114__NTH (stpncpy (char *__dest, const char *__src, size_t __n))
8215c9ec
UD
115{
116 if (__bos (__dest) != (size_t) -1
8ff5e0ec 117 && (!__builtin_constant_p (__n) || __n > __bos (__dest)))
8215c9ec
UD
118 return __stpncpy_chk (__dest, __src, __n, __bos (__dest));
119 return __stpncpy_alias (__dest, __src, __n);
120}
7163ace3 121#endif
8215c9ec
UD
122
123
5ac3ea17 124__fortify_function char *
a784e502 125__NTH (strcat (char *__restrict __dest, const char *__restrict __src))
de1c3ebb 126{
2a3224c5 127 return __builtin___strcat_chk (__dest, __src, __glibc_objsize (__dest));
de1c3ebb 128}
b5cc329c
UD
129
130
5ac3ea17 131__fortify_function char *
a784e502 132__NTH (strncat (char *__restrict __dest, const char *__restrict __src,
de1c3ebb
UD
133 size_t __len))
134{
2a3224c5
SP
135 return __builtin___strncat_chk (__dest, __src, __len,
136 __glibc_objsize (__dest));
de1c3ebb 137}
09a596cc
ZW
138
139#endif /* bits/string_fortified.h */