diff options
author | Zack Weinberg <zackw@panix.com> | 2016-11-21 08:16:27 -0500 |
---|---|---|
committer | Zack Weinberg <zackw@panix.com> | 2017-02-25 09:47:51 -0500 |
commit | 7caa5054afc1754a871333b1539e08a4af79444e (patch) | |
tree | a88f80370a89a6a7a2b2e26d3e3f0f51131fef32 /libio | |
parent | 4f5a9afffb7f1fdb330b0f8dcca196a439ac07a8 (diff) | |
download | glibc-7caa5054afc1754a871333b1539e08a4af79444e.tar.gz glibc-7caa5054afc1754a871333b1539e08a4af79444e.tar.xz glibc-7caa5054afc1754a871333b1539e08a4af79444e.zip |
Clean up conditionals for declaration of gets.
gets has the dubious honor of being the only C89 library feature that has been completely removed from the current C and C++ standards. glibc follows suit by not declaring it in _GNU_SOURCE mode either, but it remains present in older compatibility modes. Internally, two test cases need to see stdio.h make the declaration, but all our internal code is of course compiled under _GNU_SOURCE. This is currently kludged by duplicating the gets declaration, fortify wrapper and all, in include/stdio.h. Also, the conditional in the public headers for deciding when to declare gets is complicated and repeated in two places. This patch adds a new macro to features.h that encapsulates the complicated rule for when to declare gets. stdio.h and bits/stdio2.h then simply test __GLIBC_USE (DEPRECATED_GETS), and instead of having a duplicate gets declaration in include/stdio.h, debug/tst-chk1.c and stdio-common/tst-gets.c can force gets to be declared. * include/features.h (__GLIBC_USE_DEPRECATED_GETS): New macro. * libio/stdio.h, libio/bits/stdio2.h: Condition gets on __GLIBC_USE (DEPRECATED_GETS). Update comments to indicate gets was removed from C++ in C++14. * include/stdio.h: Remove redundant declaration of gets. * debug/tst-chk1.c, stdio-common/tst-gets.c: Force gets to be declared, since we are testing it. * stdio-common/Makefile (tst-gets.c): Compile with -Wno-deprecated-declarations. * debug/Makefile (tst-chk1.c, tst-chk2.c, tst-chk3.c, tst-chk4.cc) (tst-chk5.cc, tst-chk6.cc, tst-lfschk1.c, tst-lfschk2.c) (tst-lfschk3.c, tst-lfschk4.cc, tst-lfschk5.cc, tst-lfschk6.cc): Compile with -Wno-deprecated-declarations.
Diffstat (limited to 'libio')
-rw-r--r-- | libio/bits/stdio2.h | 3 | ||||
-rw-r--r-- | libio/stdio.h | 13 |
2 files changed, 6 insertions, 10 deletions
diff --git a/libio/bits/stdio2.h b/libio/bits/stdio2.h index e31386dbd7..e9f9d6952b 100644 --- a/libio/bits/stdio2.h +++ b/libio/bits/stdio2.h @@ -222,8 +222,7 @@ __NTH (obstack_vprintf (struct obstack *__restrict __obstack, #endif -#if !defined __USE_ISOC11 \ - || (defined __cplusplus && __cplusplus <= 201103L && !defined __USE_GNU) +#if __GLIBC_USE (DEPRECATED_GETS) extern char *__gets_chk (char *__str, size_t) __wur; extern char *__REDIRECT (__gets_warn, (char *__str), gets) __wur __warnattr ("please use fgets or getline instead, gets can't " diff --git a/libio/stdio.h b/libio/stdio.h index a589e367a2..c4f734cb3c 100644 --- a/libio/stdio.h +++ b/libio/stdio.h @@ -625,16 +625,13 @@ __BEGIN_NAMESPACE_STD extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream) __wur; -#if !defined __USE_ISOC11 \ - || (defined __cplusplus && __cplusplus <= 201103L) +#if __GLIBC_USE (DEPRECATED_GETS) /* Get a newline-terminated string from stdin, removing the newline. - DO NOT USE THIS FUNCTION!! There is no limit on how much it will read. - The function has been officially removed in ISO C11. This opportunity - is used to also remove it from the GNU feature list. It is now only - available when explicitly using an old ISO C, Unix, or POSIX standard. - GCC defines _GNU_SOURCE when building C++ code and the function is still - in C++11, so it is also available for C++. + This function is impossible to use safely. It has been officially + removed from ISO C11 and ISO C++14, and we have also removed it + from the _GNU_SOURCE feature list. It remains available when + explicitly using an old ISO C, Unix, or POSIX standard. This function is a possible cancellation point and therefore not marked with __THROW. */ |