wchar.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef _SSP_WCHAR_H_
  2. #define _SSP_WCHAR_H_
  3. #include <sys/cdefs.h>
  4. #include <ssp/ssp.h>
  5. #if __SSP_FORTIFY_LEVEL > 0
  6. /* wide character variant, __wlen is number of wchar_t */
  7. #define __ssp_redirect_wc(rtype, fun, args, call, cond, bos) \
  8. __ssp_decl(rtype, fun, args) \
  9. { \
  10. if (cond) \
  11. __ssp_check(__buf, __wlen * sizeof(wchar_t), bos); \
  12. return __ssp_real_(fun) call; \
  13. }
  14. #define __ssp_bos_wicheck3(fun) \
  15. __ssp_redirect_wc(wchar_t *, fun, \
  16. (wchar_t *__buf, const wchar_t *__src, size_t __wlen), \
  17. (__buf, __src, __wlen), 1, __ssp_bos0)
  18. #define __ssp_bos_wicheck3_restrict(fun) \
  19. __ssp_redirect_wc(wchar_t *, fun, \
  20. (wchar_t *__restrict __buf, const wchar_t *__restrict __src, size_t __wlen), \
  21. (__buf, __src, __wlen), 1, __ssp_bos0)
  22. #define __ssp_bos_wicheck2_restrict(fun) \
  23. __ssp_decl(wchar_t *, fun, (wchar_t *__restrict __buf, const wchar_t *__restrict __src)) \
  24. { \
  25. __ssp_check(__buf, (wcslen(__src) + 1) * sizeof(wchar_t), __ssp_bos0); \
  26. return __ssp_real_(fun) (__buf, __src); \
  27. }
  28. __BEGIN_DECLS
  29. #if __POSIX_VISIBLE >= 200809
  30. __ssp_bos_wicheck2_restrict(wcpcpy)
  31. __ssp_bos_wicheck3_restrict(wcpncpy)
  32. #endif
  33. __ssp_bos_wicheck2_restrict(wcscpy)
  34. __ssp_bos_wicheck2_restrict(wcscat)
  35. __ssp_bos_wicheck3_restrict(wcsncpy)
  36. __ssp_bos_wicheck3_restrict(wcsncat)
  37. __ssp_bos_wicheck3_restrict(wmemcpy)
  38. __ssp_bos_wicheck3(wmemmove)
  39. #if __GNU_VISIBLE
  40. __ssp_bos_wicheck3_restrict(wmempcpy)
  41. #endif
  42. __ssp_redirect_wc(wchar_t *, wmemset, \
  43. (wchar_t *__buf, wchar_t __src, size_t __wlen), \
  44. (__buf, __src, __wlen), 1, __ssp_bos0)
  45. __ssp_decl(size_t, wcrtomb, (char *__buf, wchar_t __src, mbstate_t *__ps))
  46. {
  47. if (__buf != NULL && __src != L'\0')
  48. __ssp_check(__buf, sizeof(wchar_t), __ssp_bos);
  49. return __ssp_real_wcrtomb (__buf, __src, __ps);
  50. }
  51. __ssp_redirect_wc(size_t, mbsrtowcs, \
  52. (wchar_t *__buf, const char **__src, size_t __wlen, mbstate_t *__ps), \
  53. (__buf, __src, __wlen, __ps), __buf != NULL, __ssp_bos)
  54. __ssp_redirect_raw(size_t, wcsrtombs, \
  55. (char *__buf, const wchar_t **__src, size_t __len, mbstate_t *__ps), \
  56. (__buf, __src, __len, __ps), __buf != NULL, __ssp_bos)
  57. #if __POSIX_VISIBLE >= 200809
  58. __ssp_redirect_wc(size_t, mbsnrtowcs, \
  59. (wchar_t *__buf, const char **__src, size_t __nms, size_t __wlen, mbstate_t *__ps), \
  60. (__buf, __src, __nms, __wlen, __ps), __buf != NULL, __ssp_bos)
  61. __ssp_redirect_raw(size_t, wcsnrtombs, \
  62. (char *__buf, const wchar_t **__src, size_t __nwc, size_t __len, mbstate_t *__ps), \
  63. (__buf, __src, __nwc, __len, __ps), __buf != NULL, __ssp_bos)
  64. #endif
  65. __ssp_decl(wchar_t *, fgetws, (wchar_t *__restrict __buf, int __wlen, __FILE *__restrict __fp))
  66. {
  67. if (__wlen > 0)
  68. __ssp_check(__buf, (size_t)__wlen * sizeof(wchar_t) , __ssp_bos);
  69. return __ssp_real_fgetws(__buf, __wlen, __fp);
  70. }
  71. #if __GNU_VISIBLE
  72. __ssp_decl(wchar_t *, fgetws_unlocked, (wchar_t *__buf, int __wlen, __FILE *__fp))
  73. {
  74. if (__wlen > 0)
  75. __ssp_check(__buf, (size_t)__wlen * sizeof(wchar_t) , __ssp_bos);
  76. return __ssp_real_fgetws_unlocked(__buf, __wlen, __fp);
  77. }
  78. #endif /* __GNU_VISIBLE */
  79. __END_DECLS
  80. #endif /* __SSP_FORTIFY_LEVEL > 0 */
  81. #endif /* _SSP_WCHAR_H_ */