stdio.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* $NetBSD: stdio.h,v 1.5 2011/07/17 20:54:34 joerg 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_STDIO_H_
  31. #define _SSP_STDIO_H_
  32. #include <ssp/ssp.h>
  33. __BEGIN_DECLS
  34. int __sprintf_chk(char *__restrict, int, size_t, const char *__restrict, ...)
  35. __printflike(4, 5);
  36. int __vsprintf_chk(char *__restrict, int, size_t, const char *__restrict,
  37. __va_list)
  38. __printflike(4, 0);
  39. int __snprintf_chk(char *__restrict, size_t, int, size_t,
  40. const char *__restrict, ...)
  41. __printflike(5, 6);
  42. int __vsnprintf_chk(char *__restrict, size_t, int, size_t,
  43. const char *__restrict, __va_list)
  44. __printflike(5, 0);
  45. char *__gets_chk(char *, size_t);
  46. __END_DECLS
  47. #if __SSP_FORTIFY_LEVEL > 0
  48. #define sprintf(str, ...) \
  49. __builtin___sprintf_chk(str, 0, __ssp_bos(str), __VA_ARGS__)
  50. #define vsprintf(str, fmt, ap) \
  51. __builtin___vsprintf_chk(str, 0, __ssp_bos(str), fmt, ap)
  52. #define snprintf(str, len, ...) \
  53. __builtin___snprintf_chk(str, len, 0, __ssp_bos(str), __VA_ARGS__)
  54. #define vsnprintf(str, len, fmt, ap) \
  55. __builtin___vsnprintf_chk(str, len, 0, __ssp_bos(str), fmt, ap)
  56. #define gets(str) \
  57. __gets_chk(str, __ssp_bos(str))
  58. __ssp_decl(char *, fgets, (char *__restrict __buf, int __len, FILE *__fp))
  59. {
  60. if (__len > 0)
  61. __ssp_check(__buf, (size_t)__len, __ssp_bos);
  62. return __ssp_real_fgets(__buf, __len, __fp);
  63. }
  64. #if __GNU_VISIBLE
  65. __ssp_decl(char *, fgets_unlocked, (char *__restrict __buf, int __len, FILE *__fp))
  66. {
  67. if (__len > 0)
  68. __ssp_check(__buf, (size_t)__len, __ssp_bos);
  69. return __ssp_real_fgets_unlocked(__buf, __len, __fp);
  70. }
  71. #endif /* __GNU_VISIBLE */
  72. __ssp_decl(size_t, fread, (void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __fp))
  73. {
  74. __ssp_check(__ptr, __size * __n, __ssp_bos0);
  75. return __ssp_real_fread(__ptr, __size, __n, __fp);
  76. }
  77. #if __MISC_VISIBLE
  78. __ssp_decl(size_t, fread_unlocked, (void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __fp))
  79. {
  80. __ssp_check(__ptr, __size * __n, __ssp_bos0);
  81. return __ssp_real_fread_unlocked(__ptr, __size, __n, __fp);
  82. }
  83. #endif /* __MISC_VISIBLE */
  84. #endif /* __SSP_FORTIFY_LEVEL > 0 */
  85. #endif /* _SSP_STDIO_H_ */