2001-02-15 20:57:43 +01:00
|
|
|
/* Tests for gets.
|
2017-01-01 01:14:16 +01:00
|
|
|
Copyright (C) 2001-2017 Free Software Foundation, Inc.
|
2001-07-06 06:58:11 +02:00
|
|
|
This file is part of the GNU C Library.
|
2001-02-15 20:57:43 +01:00
|
|
|
Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 06:58:11 +02:00
|
|
|
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.
|
2001-02-15 20:57:43 +01:00
|
|
|
|
|
|
|
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
|
2001-07-06 06:58:11 +02:00
|
|
|
Lesser General Public License for more details.
|
2001-02-15 20:57:43 +01:00
|
|
|
|
2001-07-06 06:58:11 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-10 00:18:22 +01:00
|
|
|
License along with the GNU C Library; if not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
2001-02-15 20:57:43 +01:00
|
|
|
|
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.
2016-11-21 14:16:27 +01:00
|
|
|
/* This file tests gets. Force it to be declared. */
|
|
|
|
#include <features.h>
|
|
|
|
#undef __GLIBC_USE_DEPRECATED_GETS
|
|
|
|
#define __GLIBC_USE_DEPRECATED_GETS 1
|
|
|
|
|
2001-02-15 20:57:43 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2011-12-27 15:53:32 +01:00
|
|
|
|
2014-11-05 10:54:08 +01:00
|
|
|
static int
|
|
|
|
do_test (void)
|
2001-02-15 20:57:43 +01:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2014-11-05 10:54:08 +01:00
|
|
|
|
|
|
|
#define TEST_FUNCTION do_test ()
|
|
|
|
#include "../test-skeleton.c"
|