Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

116 rindas
4.8KB

  1. /* $NetBSD: string.h,v 1.13 2014/11/29 13:23:48 pooka Exp $ */
  2. /*-
  3. * Copyright (c) 2006 The NetBSD Foundation, Inc.
  4. * All rights reserved.
  5. *
  6. * This code is derived from software contributed to The NetBSD Foundation
  7. * by Christos Zoulas.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  19. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  20. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  22. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef _SSP_STRING_H_
  31. #define _SSP_STRING_H_
  32. #include <sys/cdefs.h>
  33. #include <ssp/ssp.h>
  34. __BEGIN_DECLS
  35. void *__memcpy_chk(void *, const void *, size_t, size_t);
  36. void *__memmove_chk(void *, void *, size_t, size_t);
  37. void *__mempcpy_chk(void *, const void *, size_t, size_t);
  38. void *__memset_chk(void *, int, size_t, size_t);
  39. char *__stpcpy_chk(char *, const char *, size_t);
  40. char *__strcat_chk(char *, const char *, size_t);
  41. char *__strcpy_chk(char *, const char *, size_t);
  42. char *__strncat_chk(char *, const char *, size_t, size_t);
  43. char *__strncpy_chk(char *, const char *, size_t, size_t);
  44. __END_DECLS
  45. #if __SSP_FORTIFY_LEVEL > 0
  46. #define __ssp_bos_check3(fun, dst, src, len) \
  47. ((__ssp_bos0(dst) != (size_t)-1) ? \
  48. __builtin___ ## fun ## _chk(dst, src, len, __ssp_bos0(dst)) : \
  49. __ ## fun ## _ichk(dst, src, len))
  50. #define __ssp_bos_check2(fun, dst, src) \
  51. ((__ssp_bos0(dst) != (size_t)-1) ? \
  52. __builtin___ ## fun ## _chk(dst, src, __ssp_bos0(dst)) : \
  53. __ ## fun ## _ichk(dst, src))
  54. #define __ssp_bos_icheck3_restrict(fun, type1, type2) \
  55. __ssp_inline type1 __ ## fun ## _ichk(type1 __restrict, type2 __restrict, size_t); \
  56. __ssp_inline type1 \
  57. __ ## fun ## _ichk(type1 __restrict dst, type2 __restrict src, size_t len) { \
  58. return __builtin___ ## fun ## _chk(dst, src, len, __ssp_bos0(dst)); \
  59. }
  60. #define __ssp_bos_icheck3(fun, type1, type2) \
  61. __ssp_inline type1 __ ## fun ## _ichk(type1, type2, size_t); \
  62. __ssp_inline type1 \
  63. __ ## fun ## _ichk(type1 dst, type2 src, size_t len) { \
  64. return __builtin___ ## fun ## _chk(dst, src, len, __ssp_bos0(dst)); \
  65. }
  66. #define __ssp_bos_icheck2_restrict(fun, type1, type2) \
  67. __ssp_inline type1 __ ## fun ## _ichk(type1, type2); \
  68. __ssp_inline type1 \
  69. __ ## fun ## _ichk(type1 __restrict dst, type2 __restrict src) { \
  70. return __builtin___ ## fun ## _chk(dst, src, __ssp_bos0(dst)); \
  71. }
  72. __BEGIN_DECLS
  73. __ssp_bos_icheck3_restrict(memcpy, void *, const void *)
  74. __ssp_bos_icheck3(memmove, void *, const void *)
  75. __ssp_bos_icheck3_restrict(mempcpy, void *, const void *)
  76. __ssp_bos_icheck3(memset, void *, int)
  77. __ssp_bos_icheck2_restrict(stpcpy, char *, const char *)
  78. #if __GNUC_PREREQ__(4,8) || defined(__clang__)
  79. __ssp_bos_icheck3_restrict(stpncpy, char *, const char *)
  80. #endif
  81. __ssp_bos_icheck2_restrict(strcpy, char *, const char *)
  82. __ssp_bos_icheck2_restrict(strcat, char *, const char *)
  83. __ssp_bos_icheck3_restrict(strncpy, char *, const char *)
  84. __ssp_bos_icheck3_restrict(strncat, char *, const char *)
  85. __END_DECLS
  86. #define memcpy(dst, src, len) __ssp_bos_check3(memcpy, dst, src, len)
  87. #define memmove(dst, src, len) __ssp_bos_check3(memmove, dst, src, len)
  88. #if __GNU_VISIBLE
  89. #define mempcpy(dst, src, len) __ssp_bos_check3(mempcpy, dst, src, len)
  90. #endif
  91. #define memset(dst, val, len) __ssp_bos_check3(memset, dst, val, len)
  92. #if __POSIX_VISIBLE >= 200809
  93. #define stpcpy(dst, src) __ssp_bos_check2(stpcpy, dst, src)
  94. #if __GNUC_PREREQ__(4,8) || defined(__clang__)
  95. #define stpncpy(dst, src, len) __ssp_bos_check3(stpncpy, dst, src, len)
  96. #endif
  97. #endif
  98. #define strcpy(dst, src) __ssp_bos_check2(strcpy, dst, src)
  99. #define strcat(dst, src) __ssp_bos_check2(strcat, dst, src)
  100. #define strncpy(dst, src, len) __ssp_bos_check3(strncpy, dst, src, len)
  101. #define strncat(dst, src, len) __ssp_bos_check3(strncat, dst, src, len)
  102. #endif /* __SSP_FORTIFY_LEVEL > 0 */
  103. #endif /* _SSP_STRING_H_ */