1/* Checking macros for string functions. 2 Copyright (C) 2004-2022 Free Software Foundation, Inc. 3 4This file is part of GCC. 5 6GCC is free software; you can redistribute it and/or modify it under 7the terms of the GNU General Public License as published by the Free 8Software Foundation; either version 3, or (at your option) any later 9version. 10 11In addition to the permissions in the GNU General Public License, the 12Free Software Foundation gives you unlimited permission to link the 13compiled version of this file into combinations with other programs, 14and to distribute those combinations without any restriction coming 15from the use of this file. (The General Public License restrictions 16do apply in other respects; for example, they cover modification of 17the file, and distribution when not linked into a combine 18executable.) 19 20GCC is distributed in the hope that it will be useful, but WITHOUT ANY 21WARRANTY; without even the implied warranty of MERCHANTABILITY or 22FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 23for more details. 24 25Under Section 7 of GPL version 3, you are granted additional 26permissions described in the GCC Runtime Library Exception, version 273.1, as published by the Free Software Foundation. 28 29You should have received a copy of the GNU General Public License and 30a copy of the GCC Runtime Library Exception along with this program; 31see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 32<http://www.gnu.org/licenses/>. */ 33 34 35#ifndef _SSP_STRING_H 36#define _SSP_STRING_H 1 37 38#include <ssp.h> 39#include_next <string.h> 40 41#if __SSP_FORTIFY_LEVEL > 0 42 43#undef memcpy 44#undef memmove 45#undef memset 46#undef strcat 47#undef strcpy 48#undef strncat 49#undef strncpy 50#undef mempcpy 51#undef stpcpy 52#undef bcopy 53#undef bzero 54 55#define memcpy(dest, src, len) \ 56 ((__ssp_bos0 (dest) != (size_t) -1) \ 57 ? __builtin___memcpy_chk (dest, src, len, __ssp_bos0 (dest)) \ 58 : __memcpy_ichk (dest, src, len)) 59static inline __attribute__((__always_inline__)) void * 60__memcpy_ichk (void *__restrict__ __dest, const void *__restrict__ __src, 61 size_t __len) 62{ 63 return __builtin___memcpy_chk (__dest, __src, __len, __ssp_bos0 (__dest)); 64} 65 66 67#define memmove(dest, src, len) \ 68 ((__ssp_bos0 (dest) != (size_t) -1) \ 69 ? __builtin___memmove_chk (dest, src, len, __ssp_bos0 (dest)) \ 70 : __memmove_ichk (dest, src, len)) 71static inline __attribute__((__always_inline__)) void * 72__memmove_ichk (void *__dest, const void *__src, size_t __len) 73{ 74 return __builtin___memmove_chk (__dest, __src, __len, __ssp_bos0 (__dest)); 75} 76 77 78#define mempcpy(dest, src, len) \ 79 ((__ssp_bos0 (dest) != (size_t) -1) \ 80 ? __builtin___mempcpy_chk (dest, src, len, __ssp_bos0 (dest)) \ 81 : __mempcpy_ichk (dest, src, len)) 82static inline __attribute__((__always_inline__)) void * 83__mempcpy_ichk (void *__restrict__ __dest, const void *__restrict__ __src, 84 size_t __len) 85{ 86 return __builtin___mempcpy_chk (__dest, __src, __len, __ssp_bos0 (__dest)); 87} 88 89 90#define memset(dest, ch, len) \ 91 ((__ssp_bos0 (dest) != (size_t) -1) \ 92 ? __builtin___memset_chk (dest, ch, len, __ssp_bos0 (dest)) \ 93 : __memset_ichk (dest, ch, len)) 94static inline __attribute__((__always_inline__)) void * 95__memset_ichk (void *__dest, int __ch, size_t __len) 96{ 97 return __builtin___memset_chk (__dest, __ch, __len, __ssp_bos0 (__dest)); 98} 99 100#define bcopy(src, dest, len) ((void) \ 101 ((__ssp_bos0 (dest) != (size_t) -1) \ 102 ? __builtin___memmove_chk (dest, src, len, __ssp_bos0 (dest)) \ 103 : __memmove_ichk (dest, src, len))) 104#define bzero(dest, len) ((void) \ 105 ((__ssp_bos0 (dest) != (size_t) -1) \ 106 ? __builtin___memset_chk (dest, '\0', len, __ssp_bos0 (dest)) \ 107 : __memset_ichk (dest, '\0', len))) 108 109 110#define strcpy(dest, src) \ 111 ((__ssp_bos (dest) != (size_t) -1) \ 112 ? __builtin___strcpy_chk (dest, src, __ssp_bos (dest)) \ 113 : __strcpy_ichk (dest, src)) 114static inline __attribute__((__always_inline__)) char * 115__strcpy_ichk (char *__restrict__ __dest, const char *__restrict__ __src) 116{ 117 return __builtin___strcpy_chk (__dest, __src, __ssp_bos (__dest)); 118} 119 120 121#define stpcpy(dest, src) \ 122 ((__ssp_bos (dest) != (size_t) -1) \ 123 ? __builtin___stpcpy_chk (dest, src, __ssp_bos (dest)) \ 124 : __stpcpy_ichk (dest, src)) 125static inline __attribute__((__always_inline__)) char * 126__stpcpy_ichk (char *__restrict__ __dest, const char *__restrict__ __src) 127{ 128 return __builtin___stpcpy_chk (__dest, __src, __ssp_bos (__dest)); 129} 130 131 132#define strncpy(dest, src, len) \ 133 ((__ssp_bos (dest) != (size_t) -1) \ 134 ? __builtin___strncpy_chk (dest, src, len, __ssp_bos (dest)) \ 135 : __strncpy_ichk (dest, src, len)) 136static inline __attribute__((__always_inline__)) char * 137__strncpy_ichk (char *__restrict__ __dest, const char *__restrict__ __src, 138 size_t __len) 139{ 140 return __builtin___strncpy_chk (__dest, __src, __len, __ssp_bos (__dest)); 141} 142 143 144#define strcat(dest, src) \ 145 ((__ssp_bos (dest) != (size_t) -1) \ 146 ? __builtin___strcat_chk (dest, src, __ssp_bos (dest)) \ 147 : __strcat_ichk (dest, src)) 148static inline __attribute__((__always_inline__)) char * 149__strcat_ichk (char *__restrict__ __dest, const char *__restrict__ __src) 150{ 151 return __builtin___strcat_chk (__dest, __src, __ssp_bos (__dest)); 152} 153 154 155#define strncat(dest, src, len) \ 156 ((__ssp_bos (dest) != (size_t) -1) \ 157 ? __builtin___strncat_chk (dest, src, len, __ssp_bos (dest)) \ 158 : __strncat_ichk (dest, src, len)) 159static inline __attribute__((__always_inline__)) char * 160__strncat_ichk (char *__restrict__ __dest, const char *__restrict__ __src, 161 size_t __len) 162{ 163 return __builtin___strncat_chk (__dest, __src, __len, __ssp_bos (__dest)); 164} 165 166#endif /* __SSP_FORTIFY_LEVEL > 0 */ 167#endif /* _SSP_STRING_H */ 168