diff options
Diffstat (limited to 'libio/bits')
-rw-r--r-- | libio/bits/stdio2.h | 57 |
1 files changed, 42 insertions, 15 deletions
diff --git a/libio/bits/stdio2.h b/libio/bits/stdio2.h index 4181f8a9a9..0582edbccb 100644 --- a/libio/bits/stdio2.h +++ b/libio/bits/stdio2.h @@ -72,18 +72,45 @@ extern int __vprintf_chk (int __flag, __const char *__restrict __format, #endif -extern char *__gets_chk (char *__str, size_t); -#define gets(__str) \ - ((__bos (__str) == (size_t) -1) \ - ? gets (__str) : __gets_chk (__str, __bos (__str))) - -extern char *__fgets_chk (char *s, size_t size, int n, FILE *stream); -#define fgets(__str, __n, __fp) \ - ((__bos (__str) == (size_t) -1) \ - ? fgets (__str, __n, __fp) : __fgets_chk (__str, __bos (__str), __n, __fp)) - -extern char *__fgets_unlocked_chk (char *s, size_t size, int n, FILE *stream); -#define fgets_unlocked(__str, __n, __fp) \ - ((__bos (__str) == (size_t) -1) \ - ? fgets_unlocked (__str, __n, __fp) \ - : __fgets_unlocked_chk (__str, __bos (__str), __n, __fp)) +extern char *__gets_chk (char *__str, size_t) __wur; +extern char *__REDIRECT (__gets_alias, (char *__str), gets) __wur; + +extern __always_inline __wur char * +gets (char *__str) +{ + if (__bos (__str) != (size_t) -1) + return __gets_chk (__str, __bos (__str)); + return __gets_alias (__str); +} + +extern char *__fgets_chk (char *__restrict __s, size_t __size, int __n, + FILE *__restrict __stream) __wur; +extern char *__REDIRECT (__fgets_alias, + (char *__restrict __s, int __n, + FILE *__restrict __stream), fgets) __wur; + +extern __always_inline __wur char * +fgets (char *__restrict __s, int __n, FILE *__restrict __stream) +{ + if (__bos (__s) != (size_t) -1 + && (!__builtin_constant_p (__n) || (size_t) __n > __bos (__s))) + return __fgets_chk (__s, __bos (__s), __n, __stream); + return __fgets_alias (__s, __n, __stream); +} + +#ifdef __USE_GNU +extern char *__fgets_unlocked_chk (char *__restrict __s, size_t __size, + int __n, FILE *__restrict __stream) __wur; +extern char *__REDIRECT (__fgets_unlocked_alias, + (char *__restrict __s, int __n, + FILE *__restrict __stream), fgets_unlocked) __wur; + +extern __always_inline __wur char * +fgets_unlocked (char *__restrict __s, int __n, FILE *__restrict __stream) +{ + if (__bos (__s) != (size_t) -1 + && (!__builtin_constant_p (__n) || (size_t) __n > __bos (__s))) + return __fgets_unlocked_chk (__s, __bos (__s), __n, __stream); + return __fgets_unlocked_alias (__s, __n, __stream); +} +#endif |