string.h 5.6 KB

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