1 /* Checking macros for stdio functions.
2 Copyright (C) 2004, 2005 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 # error "Never include <bits/stdio2.h> directly; use <stdio.h> instead."
24 extern int __sprintf_chk (char *__restrict __s
, int __flag
, size_t __slen
,
25 __const
char *__restrict __format
, ...) __THROW
;
26 extern int __vsprintf_chk (char *__restrict __s
, int __flag
, size_t __slen
,
27 __const
char *__restrict __format
,
28 _G_va_list __ap
) __THROW
;
30 #define sprintf(str, ...) \
31 __builtin___sprintf_chk (str, __USE_FORTIFY_LEVEL - 1, __bos (str), \
33 #define vsprintf(str, fmt, ap) \
34 __builtin___vsprintf_chk (str, __USE_FORTIFY_LEVEL - 1, __bos (str), fmt, ap)
36 #if defined __USE_BSD || defined __USE_ISOC99 || defined __USE_UNIX98
38 extern int __snprintf_chk (char *__restrict __s
, size_t __n
, int __flag
,
39 size_t __slen
, __const
char *__restrict __format
,
41 extern int __vsnprintf_chk (char *__restrict __s
, size_t __n
, int __flag
,
42 size_t __slen
, __const
char *__restrict __format
,
43 _G_va_list __ap
) __THROW
;
45 # define snprintf(str, len, ...) \
46 __builtin___snprintf_chk (str, len, __USE_FORTIFY_LEVEL - 1, __bos (str), \
48 # define vsnprintf(str, len, fmt, ap) \
49 __builtin___vsnprintf_chk (str, len, __USE_FORTIFY_LEVEL - 1, __bos (str), \
54 #if __USE_FORTIFY_LEVEL > 1
56 extern int __fprintf_chk (FILE *__restrict __stream
, int __flag
,
57 __const
char *__restrict __format
, ...);
58 extern int __printf_chk (int __flag
, __const
char *__restrict __format
, ...);
59 extern int __vfprintf_chk (FILE *__restrict __stream
, int __flag
,
60 __const
char *__restrict __format
, _G_va_list __ap
);
61 extern int __vprintf_chk (int __flag
, __const
char *__restrict __format
,
64 # if __GNUC_PREREQ (4, 0)
65 # define printf(...) \
66 __printf_chk (__USE_FORTIFY_LEVEL - 1, __VA_ARGS__)
67 # define fprintf(stream, ...) \
68 __fprintf_chk (stream, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__)
69 # define vprintf(format, ap) \
70 __vprintf_chk (__USE_FORTIFY_LEVEL - 1, format, ap)
71 # define vfprintf(stream, format, ap) \
72 __vfprintf_chk (stream, __USE_FORTIFY_LEVEL - 1, format, ap)
74 # define printf(...) \
75 __builtin___printf_chk (__USE_FORTIFY_LEVEL - 1, __VA_ARGS__)
76 # define fprintf(stream, ...) \
77 __builtin___fprintf_chk (stream, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__)
78 # define vprintf(format, ap) \
79 __builtin___vprintf_chk (__USE_FORTIFY_LEVEL - 1, format, ap)
80 # define vfprintf(stream, format, ap) \
81 __builtin___vfprintf_chk (stream, __USE_FORTIFY_LEVEL - 1, format, ap)
86 extern char *__gets_chk (char *__str
, size_t) __wur
;
87 extern char *__REDIRECT (__gets_alias
, (char *__str
), gets
) __wur
;
89 extern __always_inline __wur
char *
92 if (__bos (__str
) != (size_t) -1)
93 return __gets_chk (__str
, __bos (__str
));
94 return __gets_alias (__str
);
97 extern void __chk_fail (void) __attribute__((__noreturn__
));
98 extern char *__REDIRECT (__fgets_alias
,
99 (char *__restrict __s
, int __n
,
100 FILE *__restrict __stream
), fgets
) __wur
;
102 extern __always_inline __wur
char *
103 fgets (char *__restrict __s
, int __n
, FILE *__restrict __stream
)
105 if (__bos (__s
) != (size_t) -1 && (size_t) __n
> __bos (__s
))
107 return __fgets_alias (__s
, __n
, __stream
);
111 extern char *__REDIRECT (__fgets_unlocked_alias
,
112 (char *__restrict __s
, int __n
,
113 FILE *__restrict __stream
), fgets_unlocked
) __wur
;
115 extern __always_inline __wur
char *
116 fgets_unlocked (char *__restrict __s
, int __n
, FILE *__restrict __stream
)
118 if (__bos (__s
) != (size_t) -1 && (size_t) __n
> __bos (__s
))
120 return __fgets_unlocked_alias (__s
, __n
, __stream
);