aboutsummaryrefslogtreecommitdiff
path: root/nss/test-netdb.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2001-08-23 08:36:47 +0000
committerRoland McGrath <roland@gnu.org>2001-08-23 08:36:47 +0000
commit9efc8b95af3b3e832d7d3660119c3d487d40d16e (patch)
treefbd62af5cbd4a910ce1da1e9c1ef4d5b8b6b077d /nss/test-netdb.c
parentc12aa8015699d66a193c3c183b4f1d1a72bb92c1 (diff)
downloadglibc-9efc8b95af3b3e832d7d3660119c3d487d40d16e.zip
glibc-9efc8b95af3b3e832d7d3660119c3d487d40d16e.tar.gz
glibc-9efc8b95af3b3e832d7d3660119c3d487d40d16e.tar.bz2
* libio/tst-ungetwc1.c (main): Add a const to quiet a warning.
* nss/test-netdb.c (test_hosts): Don't use MAXHOSTNAMELEN. Instead, use dynamic buffer to test gethostname's ENAMETOOLONG error.
Diffstat (limited to 'nss/test-netdb.c')
-rw-r--r--nss/test-netdb.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/nss/test-netdb.c b/nss/test-netdb.c
index f527240..8ae6d12 100644
--- a/nss/test-netdb.c
+++ b/nss/test-netdb.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1998,99,2000,01 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Andreas Jaeger <aj@suse.de>, 1998.
@@ -40,6 +40,7 @@
#include <sys/param.h>
#include <sys/socket.h>
#include <unistd.h>
+#include <errno.h>
#include "nss.h"
/*
@@ -138,8 +139,8 @@ static void
test_hosts (void)
{
struct hostent *hptr1, *hptr2;
- char name[MAXHOSTNAMELEN];
- size_t namelen = sizeof(name);
+ char *name = NULL;
+ size_t namelen = 0;
struct in_addr ip;
hptr1 = gethostbyname ("localhost");
@@ -176,6 +177,11 @@ test_hosts (void)
hptr1 = gethostbyname2 ("localhost", AF_INET);
output_hostent ("gethostbyname2 (\"localhost\", AF_INET)", hptr1);
+ while (gethostname (name, namelen) < 0 && errno == ENAMETOOLONG)
+ {
+ namelen += 2; /* tiny increments to test a lot */
+ name = realloc (name, namelen);
+ }
if (gethostname (name, namelen) == 0)
{
printf ("Hostname: %s\n", name);