1169695Skan/* Checking macros for stdio functions. 2169695Skan Copyright (C) 2004, 2005 Free Software Foundation, Inc. 3169695Skan 4169695SkanThis file is part of GCC. 5169695Skan 6169695SkanGCC is free software; you can redistribute it and/or modify it under 7169695Skanthe terms of the GNU General Public License as published by the Free 8169695SkanSoftware Foundation; either version 2, or (at your option) any later 9169695Skanversion. 10169695Skan 11169695SkanIn addition to the permissions in the GNU General Public License, the 12169695SkanFree Software Foundation gives you unlimited permission to link the 13169695Skancompiled version of this file into combinations with other programs, 14169695Skanand to distribute those combinations without any restriction coming 15169695Skanfrom the use of this file. (The General Public License restrictions 16169695Skando apply in other respects; for example, they cover modification of 17169695Skanthe file, and distribution when not linked into a combine 18169695Skanexecutable.) 19169695Skan 20169695SkanGCC is distributed in the hope that it will be useful, but WITHOUT ANY 21169695SkanWARRANTY; without even the implied warranty of MERCHANTABILITY or 22169695SkanFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 23169695Skanfor more details. 24169695Skan 25169695SkanYou should have received a copy of the GNU General Public License 26169695Skanalong with GCC; see the file COPYING. If not, write to the Free 27169695SkanSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 28169695Skan02110-1301, USA. */ 29169695Skan 30169695Skan/* As a special exception, if you link this library with files compiled with 31169695Skan GCC to produce an executable, this does not cause the resulting executable 32169695Skan to be covered by the GNU General Public License. This exception does not 33169695Skan however invalidate any other reasons why the executable file might be 34169695Skan covered by the GNU General Public License. */ 35169695Skan 36169695Skan#ifndef _SSP_STDIO_H 37169695Skan#define _SSP_STDIO_H 1 38169695Skan 39169695Skan#include <ssp.h> 40169695Skan#include_next <stdio.h> 41169695Skan 42169695Skan#if __SSP_FORTIFY_LEVEL > 0 43169695Skan 44169695Skan#include <stdarg.h> 45169695Skan 46169695Skan#undef sprintf 47169695Skan#undef vsprintf 48169695Skan#undef snprintf 49169695Skan#undef vsnprintf 50169695Skan#undef gets 51169695Skan#undef fgets 52169695Skan 53169695Skanextern int __sprintf_chk (char *__restrict__ __s, int __flag, size_t __slen, 54169695Skan __const char *__restrict__ __format, ...); 55169695Skanextern int __vsprintf_chk (char *__restrict__ __s, int __flag, size_t __slen, 56169695Skan __const char *__restrict__ __format, 57169695Skan va_list __ap); 58169695Skan 59169695Skan#define sprintf(str, ...) \ 60169695Skan __builtin___sprintf_chk (str, 0, __ssp_bos (str), \ 61169695Skan __VA_ARGS__) 62169695Skan#define vsprintf(str, fmt, ap) \ 63169695Skan __builtin___vsprintf_chk (str, 0, __ssp_bos (str), fmt, ap) 64169695Skan 65169695Skanextern int __snprintf_chk (char *__restrict__ __s, size_t __n, int __flag, 66169695Skan size_t __slen, __const char *__restrict__ __format, 67169695Skan ...); 68169695Skanextern int __vsnprintf_chk (char *__restrict__ __s, size_t __n, int __flag, 69169695Skan size_t __slen, __const char *__restrict__ __format, 70169695Skan va_list __ap); 71169695Skan 72169695Skan#define snprintf(str, len, ...) \ 73169695Skan __builtin___snprintf_chk (str, len, 0, __ssp_bos (str), __VA_ARGS__) 74169695Skan#define vsnprintf(str, len, fmt, ap) \ 75169695Skan __builtin___vsnprintf_chk (str, len, 0, __ssp_bos (str), fmt, ap) 76169695Skan 77169695Skanextern char *__gets_chk (char *__str, size_t); 78169695Skanextern char *__SSP_REDIRECT (__gets_alias, (char *__str), gets); 79169695Skan 80169695Skanextern inline __attribute__((__always_inline__)) char * 81169695Skangets (char *__str) 82169695Skan{ 83169695Skan if (__ssp_bos (__str) != (size_t) -1) 84169695Skan return __gets_chk (__str, __ssp_bos (__str)); 85169695Skan return __gets_alias (__str); 86169695Skan} 87169695Skan 88169695Skanextern char *__SSP_REDIRECT (__fgets_alias, 89169695Skan (char *__restrict__ __s, int __n, 90169695Skan FILE *__restrict__ __stream), fgets); 91169695Skan 92169695Skanextern inline __attribute__((__always_inline__)) char * 93169695Skanfgets (char *__restrict__ __s, int __n, FILE *__restrict__ __stream) 94169695Skan{ 95169695Skan if (__ssp_bos (__s) != (size_t) -1 && (size_t) __n > __ssp_bos (__s)) 96169695Skan __chk_fail (); 97169695Skan return __fgets_alias (__s, __n, __stream); 98169695Skan} 99169695Skan 100169695Skan#endif /* __SSP_FORTIFY_LEVEL > 0 */ 101169695Skan#endif /* _SSP_STDIO_H */ 102