]> git.ipfire.org Git - thirdparty/glibc.git/blame - string/bits/string3.h
Combine __USE_BSD and __USE_SVID into __USE_MISC.
[thirdparty/glibc.git] / string / bits / string3.h
CommitLineData
d4697bc9 1/* Copyright (C) 2004-2014 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
PE
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
b5cc329c
UD
17
18#ifndef _STRING_H
19# error "Never use <bits/string3.h> directly; include <string.h> instead."
20#endif
21
de1c3ebb
UD
22__warndecl (__warn_memset_zero_len,
23 "memset used with constant zero length parameter; this could be due to transposed parameters");
24
25#ifndef __cplusplus
b5cc329c
UD
26/* XXX This is temporarily. We should not redefine any of the symbols
27 and instead integrate the error checking into the original
28 definitions. */
de1c3ebb
UD
29# undef memcpy
30# undef memmove
31# undef memset
32# undef strcat
33# undef strcpy
34# undef strncat
35# undef strncpy
36# ifdef __USE_GNU
37# undef mempcpy
38# undef stpcpy
39# endif
498afc54 40# ifdef __USE_MISC
de1c3ebb
UD
41# undef bcopy
42# undef bzero
43# endif
b5cc329c
UD
44#endif
45
46
5ac3ea17 47__fortify_function void *
a784e502 48__NTH (memcpy (void *__restrict __dest, const void *__restrict __src,
de1c3ebb
UD
49 size_t __len))
50{
51 return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest));
52}
b5cc329c 53
5ac3ea17 54__fortify_function void *
a784e502 55__NTH (memmove (void *__dest, const void *__src, size_t __len))
de1c3ebb
UD
56{
57 return __builtin___memmove_chk (__dest, __src, __len, __bos0 (__dest));
58}
b5cc329c
UD
59
60#ifdef __USE_GNU
5ac3ea17 61__fortify_function void *
a784e502 62__NTH (mempcpy (void *__restrict __dest, const void *__restrict __src,
de1c3ebb
UD
63 size_t __len))
64{
65 return __builtin___mempcpy_chk (__dest, __src, __len, __bos0 (__dest));
66}
b5cc329c
UD
67#endif
68
69
553cc5f9
UD
70/* The first two tests here help to catch a somewhat common problem
71 where the second and third parameter are transposed. This is
72 especially problematic if the intended fill value is zero. In this
73 case no work is done at all. We detect these problems by referring
74 non-existing functions. */
5ac3ea17 75__fortify_function void *
de1c3ebb
UD
76__NTH (memset (void *__dest, int __ch, size_t __len))
77{
6515a01f
CM
78 if (__builtin_constant_p (__len) && __len == 0
79 && (!__builtin_constant_p (__ch) || __ch != 0))
de1c3ebb
UD
80 {
81 __warn_memset_zero_len ();
82 return __dest;
83 }
84 return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest));
85}
b5cc329c 86
498afc54 87#ifdef __USE_MISC
5ac3ea17 88__fortify_function void
a784e502 89__NTH (bcopy (const void *__src, void *__dest, size_t __len))
de1c3ebb 90{
e5dd2178 91 (void) __builtin___memmove_chk (__dest, __src, __len, __bos0 (__dest));
de1c3ebb 92}
e5dd2178 93
5ac3ea17 94__fortify_function void
de1c3ebb
UD
95__NTH (bzero (void *__dest, size_t __len))
96{
e5dd2178 97 (void) __builtin___memset_chk (__dest, '\0', __len, __bos0 (__dest));
de1c3ebb 98}
b5cc329c
UD
99#endif
100
5ac3ea17 101__fortify_function char *
a784e502 102__NTH (strcpy (char *__restrict __dest, const char *__restrict __src))
de1c3ebb
UD
103{
104 return __builtin___strcpy_chk (__dest, __src, __bos (__dest));
105}
b5cc329c
UD
106
107#ifdef __USE_GNU
5ac3ea17 108__fortify_function char *
a784e502 109__NTH (stpcpy (char *__restrict __dest, const char *__restrict __src))
de1c3ebb
UD
110{
111 return __builtin___stpcpy_chk (__dest, __src, __bos (__dest));
112}
b5cc329c
UD
113#endif
114
115
5ac3ea17 116__fortify_function char *
a784e502 117__NTH (strncpy (char *__restrict __dest, const char *__restrict __src,
de1c3ebb
UD
118 size_t __len))
119{
120 return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
121}
b5cc329c 122
8215c9ec 123// XXX We have no corresponding builtin yet.
a784e502 124extern char *__stpncpy_chk (char *__dest, const char *__src, size_t __n,
8215c9ec 125 size_t __destlen) __THROW;
a784e502 126extern char *__REDIRECT_NTH (__stpncpy_alias, (char *__dest, const char *__src,
dc4bb1c2 127 size_t __n), stpncpy);
8215c9ec 128
5ac3ea17 129__fortify_function char *
a784e502 130__NTH (stpncpy (char *__dest, const char *__src, size_t __n))
8215c9ec
UD
131{
132 if (__bos (__dest) != (size_t) -1
133 && (!__builtin_constant_p (__n) || __n <= __bos (__dest)))
134 return __stpncpy_chk (__dest, __src, __n, __bos (__dest));
135 return __stpncpy_alias (__dest, __src, __n);
136}
137
138
5ac3ea17 139__fortify_function char *
a784e502 140__NTH (strcat (char *__restrict __dest, const char *__restrict __src))
de1c3ebb
UD
141{
142 return __builtin___strcat_chk (__dest, __src, __bos (__dest));
143}
b5cc329c
UD
144
145
5ac3ea17 146__fortify_function char *
a784e502 147__NTH (strncat (char *__restrict __dest, const char *__restrict __src,
de1c3ebb
UD
148 size_t __len))
149{
150 return __builtin___strncat_chk (__dest, __src, __len, __bos (__dest));
151}