Fix ucs4le_internal_loop in error case. [BZ #19726]
[glibc.git] / posix / tst-getaddrinfo4.c
blob5a20d0e64f37014f438bf78846c67b7c4aa54e60
1 /* Test getaddrinfo return value, [BZ #15339].
2 Copyright (C) 2013-2016 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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 <http://www.gnu.org/licenses/>. */
19 #include <string.h>
20 #include <stdio.h>
21 #include <errno.h>
22 #include <netdb.h>
24 static int
25 try (const char *service, int family, int flags)
27 struct addrinfo hints, *h, *ai;
28 int res;
30 memset (&hints, 0, sizeof hints);
31 hints.ai_family = family;
32 hints.ai_flags = flags;
34 errno = 0;
35 h = (family || flags) ? &hints : NULL;
36 res = getaddrinfo ("example.net", service, h, &ai);
37 switch (res)
39 case 0:
40 case EAI_AGAIN:
41 case EAI_NONAME:
42 printf ("SUCCESS getaddrinfo(service=%s, family=%d, flags=%d): %s: %m\n",
43 service ?: "NULL", family, flags, gai_strerror (res));
44 return 0;
46 printf ("FAIL getaddrinfo(service=%s, family=%d, flags=%d): %s: %m\n",
47 service ?: "NULL", family, flags, gai_strerror (res));
48 return 1;
51 static int
52 do_test (void)
54 int err = 0;
55 err |= try (NULL, 0, 0);
56 err |= try (NULL, AF_UNSPEC, AI_ADDRCONFIG);
57 err |= try (NULL, AF_INET, 0);
58 err |= try (NULL, AF_INET6, 0);
59 err |= try ("http", 0, 0);
60 err |= try ("http", AF_UNSPEC, AI_ADDRCONFIG);
61 err |= try ("http", AF_INET, 0);
62 err |= try ("http", AF_INET6, 0);
63 return err;
66 #define TEST_FUNCTION do_test ()
67 #define TIMEOUT 10
68 #include "../test-skeleton.c"