mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-08 14:20:07 +00:00
7caa5054af
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.
72 lines
1.9 KiB
C
72 lines
1.9 KiB
C
/* Tests for gets.
|
|
Copyright (C) 2001-2017 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with the GNU C Library; if not, see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
/* This file tests gets. Force it to be declared. */
|
|
#include <features.h>
|
|
#undef __GLIBC_USE_DEPRECATED_GETS
|
|
#define __GLIBC_USE_DEPRECATED_GETS 1
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
|
|
static int
|
|
do_test (void)
|
|
{
|
|
char buf[100];
|
|
int result = 0;
|
|
|
|
if (gets (buf) != buf)
|
|
{
|
|
printf ("gets: read error: %m\n");
|
|
result = 1;
|
|
}
|
|
else if (strchr (buf, '\n') != NULL)
|
|
{
|
|
printf ("newline not stripped: \"%s\"\n", buf);
|
|
result = 1;
|
|
}
|
|
else if (strcmp (buf, "foo") != 0)
|
|
{
|
|
printf ("read mismatch: expected \"%s\", got \"%s\"\n", "foo", buf);
|
|
result = 1;
|
|
}
|
|
|
|
if (gets (buf) != buf)
|
|
{
|
|
printf ("gets: read error: %m\n");
|
|
result = 1;
|
|
}
|
|
else if (strchr (buf, '\n') != NULL)
|
|
{
|
|
printf ("newline not stripped: \"%s\"\n", buf);
|
|
result = 1;
|
|
}
|
|
else if (strcmp (buf, "bar") != 0)
|
|
{
|
|
printf ("read mismatch: expected \"%s\", got \"%s\"\n", "bar", buf);
|
|
result = 1;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#define TEST_FUNCTION do_test ()
|
|
#include "../test-skeleton.c"
|