posix: Remove alloca usage for internal fnmatch implementation
[platform/upstream/glibc.git] / posix / tst-getaddrinfo5.c
1 /* Test host lookup with double dots at the end, [BZ #16469].
2    Copyright (C) 2014-2021 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 #include <sys/types.h>
20 #include <sys/socket.h>
21 #include <netdb.h>
22 #include <stdio.h>
23 #include <string.h>
24
25 static int
26 test (void)
27 {
28   static char host1[] = "localhost..";
29   static char host2[] = "www.gnu.org..";
30   static char *hosts[] = { host1, host2 };
31   int i;
32   int pass = 0;
33
34   for (i = 0; i < sizeof (hosts) / sizeof (*hosts); i++)
35     {
36       char *host = hosts[i];
37       size_t len = strlen (host);
38       struct addrinfo *ai;
39
40       /* If the name doesn't resolve with a single dot at the
41          end, skip it.  */
42       host[len-1] = 0;
43       if (getaddrinfo (host, NULL, NULL, &ai) != 0)
44         {
45           printf ("resolving \"%s\" failed, skipping this hostname\n", host);
46           continue;
47         }
48       printf ("resolving \"%s\" worked, proceeding to test\n", host);
49       freeaddrinfo (ai);
50
51       /* If it resolved with a single dot, check that it doesn't with
52          a second trailing dot.  */
53       host[len-1] = '.';
54       if (getaddrinfo (host, NULL, NULL, &ai) == 0)
55         {
56           printf ("resolving \"%s\" worked, test failed\n", host);
57           return 1;
58         }
59       printf ("resolving \"%s\" failed, test passed\n", host);
60       pass = 1;
61     }
62
63   /* We want at least one successful name resolution for the test to
64      succeed.  */
65   return pass ? 0 : 2;
66 }
67
68 #define TEST_FUNCTION test ()
69 #include "../test-skeleton.c"