stdio.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* Checking macros for stdio functions.
  2. Copyright (C) 2004-2022 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_STDIO_H
  28. #define _SSP_STDIO_H 1
  29. #include <ssp.h>
  30. #include_next <stdio.h>
  31. #if __SSP_FORTIFY_LEVEL > 0
  32. #include <stdarg.h>
  33. #undef sprintf
  34. #undef vsprintf
  35. #undef snprintf
  36. #undef vsnprintf
  37. #undef gets
  38. #undef fgets
  39. extern int __sprintf_chk (char *__restrict__ __s, int __flag, size_t __slen,
  40. __const char *__restrict__ __format, ...);
  41. extern int __vsprintf_chk (char *__restrict__ __s, int __flag, size_t __slen,
  42. __const char *__restrict__ __format,
  43. va_list __ap);
  44. #define sprintf(str, ...) \
  45. __builtin___sprintf_chk (str, 0, __ssp_bos (str), \
  46. __VA_ARGS__)
  47. #define vsprintf(str, fmt, ap) \
  48. __builtin___vsprintf_chk (str, 0, __ssp_bos (str), fmt, ap)
  49. extern int __snprintf_chk (char *__restrict__ __s, size_t __n, int __flag,
  50. size_t __slen, __const char *__restrict__ __format,
  51. ...);
  52. extern int __vsnprintf_chk (char *__restrict__ __s, size_t __n, int __flag,
  53. size_t __slen, __const char *__restrict__ __format,
  54. va_list __ap);
  55. #define snprintf(str, len, ...) \
  56. __builtin___snprintf_chk (str, len, 0, __ssp_bos (str), __VA_ARGS__)
  57. #define vsnprintf(str, len, fmt, ap) \
  58. __builtin___vsnprintf_chk (str, len, 0, __ssp_bos (str), fmt, ap)
  59. extern char *__gets_chk (char *__str, size_t);
  60. extern char *__SSP_REDIRECT (__gets_alias, (char *__str), gets);
  61. extern inline __attribute__((__always_inline__)) char *
  62. gets (char *__str)
  63. {
  64. if (__ssp_bos (__str) != (size_t) -1)
  65. return __gets_chk (__str, __ssp_bos (__str));
  66. return __gets_alias (__str);
  67. }
  68. extern char *__SSP_REDIRECT (__fgets_alias,
  69. (char *__restrict__ __s, int __n,
  70. FILE *__restrict__ __stream), fgets);
  71. extern inline __attribute__((__always_inline__)) char *
  72. fgets (char *__restrict__ __s, int __n, FILE *__restrict__ __stream)
  73. {
  74. if (__ssp_bos (__s) != (size_t) -1 && (size_t) __n > __ssp_bos (__s))
  75. __chk_fail ();
  76. return __fgets_alias (__s, __n, __stream);
  77. }
  78. #endif /* __SSP_FORTIFY_LEVEL > 0 */
  79. #endif /* _SSP_STDIO_H */