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 # define printf(...) \
65 __printf_chk (__USE_FORTIFY_LEVEL - 1, __VA_ARGS__)
66 # define fprintf(stream, ...) \
67 __fprintf_chk (stream, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__)
68 # define vprintf(format, ap) \
69 __vprintf_chk (__USE_FORTIFY_LEVEL - 1, format, ap)
70 # define vfprintf(stream, format, ap) \
71 __vfprintf_chk (stream, __USE_FORTIFY_LEVEL - 1, format, ap)
75 extern char *__gets_chk (char *__str
, size_t) __wur
;
76 extern char *__REDIRECT (__gets_alias
, (char *__str
), gets
) __wur
;
78 extern __always_inline __wur
char *
81 if (__bos (__str
) != (size_t) -1)
82 return __gets_chk (__str
, __bos (__str
));
83 return __gets_alias (__str
);
86 extern char *__fgets_chk (char *__restrict __s
, size_t __size
, int __n
,
87 FILE *__restrict __stream
) __wur
;
88 extern char *__REDIRECT (__fgets_alias
,
89 (char *__restrict __s
, int __n
,
90 FILE *__restrict __stream
), fgets
) __wur
;
92 extern __always_inline __wur
char *
93 fgets (char *__restrict __s
, int __n
, FILE *__restrict __stream
)
95 if (__bos (__s
) != (size_t) -1
96 && (!__builtin_constant_p (__n
) || (size_t) __n
> __bos (__s
)))
97 return __fgets_chk (__s
, __bos (__s
), __n
, __stream
);
98 return __fgets_alias (__s
, __n
, __stream
);
102 extern char *__fgets_unlocked_chk (char *__restrict __s
, size_t __size
,
103 int __n
, FILE *__restrict __stream
) __wur
;
104 extern char *__REDIRECT (__fgets_unlocked_alias
,
105 (char *__restrict __s
, int __n
,
106 FILE *__restrict __stream
), fgets_unlocked
) __wur
;
108 extern __always_inline __wur
char *
109 fgets_unlocked (char *__restrict __s
, int __n
, FILE *__restrict __stream
)
111 if (__bos (__s
) != (size_t) -1
112 && (!__builtin_constant_p (__n
) || (size_t) __n
> __bos (__s
)))
113 return __fgets_unlocked_chk (__s
, __bos (__s
), __n
, __stream
);
114 return __fgets_unlocked_alias (__s
, __n
, __stream
);