1/* Tests for gets.
2 Copyright (C) 2001-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19/* This file tests gets. Force it to be declared. */
20#include <features.h>
21#undef __GLIBC_USE_DEPRECATED_GETS
22#define __GLIBC_USE_DEPRECATED_GETS 1
23
24#include <stdio.h>
25#include <string.h>
26
27
28static int
29do_test (void)
30{
31 char buf[100];
32 int result = 0;
33
34 if (gets (s: buf) != buf)
35 {
36 printf (format: "gets: read error: %m\n");
37 result = 1;
38 }
39 else if (strchr (buf, '\n') != NULL)
40 {
41 printf (format: "newline not stripped: \"%s\"\n", buf);
42 result = 1;
43 }
44 else if (strcmp (buf, "foo") != 0)
45 {
46 printf (format: "read mismatch: expected \"%s\", got \"%s\"\n", "foo", buf);
47 result = 1;
48 }
49
50 if (gets (s: buf) != buf)
51 {
52 printf (format: "gets: read error: %m\n");
53 result = 1;
54 }
55 else if (strchr (buf, '\n') != NULL)
56 {
57 printf (format: "newline not stripped: \"%s\"\n", buf);
58 result = 1;
59 }
60 else if (strcmp (buf, "bar") != 0)
61 {
62 printf (format: "read mismatch: expected \"%s\", got \"%s\"\n", "bar", buf);
63 result = 1;
64 }
65
66 return result;
67}
68
69#define TEST_FUNCTION do_test ()
70#include "../test-skeleton.c"
71

source code of glibc/stdio-common/tst-gets.c