(sysdep_routines, shared-only-routines): Don't add divdi3 here.
[glibc.git] / nss / bug-erange.c
blob5e535a0fe4563febb8af40689606dec1c91be6c0
1 /* Test case for gethostbyname_r bug when buffer expansion required. */
3 #include <netdb.h>
4 #include <arpa/inet.h>
5 #include <errno.h>
6 #include <string.h>
7 #include <stdio.h>
8 #include <stdlib.h>
10 int
11 main (void)
13 const char *host = "www.gnu.org";
15 /* This code approximates the example code in the library manual. */
17 struct hostent hostbuf, *hp;
18 size_t hstbuflen;
19 char *tmphstbuf;
20 int res;
21 int herr;
23 hstbuflen = 16; /* Make it way small to ensure ERANGE. */
24 /* Allocate buffer, remember to free it to avoid memory leakage. */
25 tmphstbuf = malloc (hstbuflen);
27 while ((res = gethostbyname_r (host, &hostbuf, tmphstbuf, hstbuflen,
28 &hp, &herr)) == ERANGE)
30 /* Enlarge the buffer. */
31 hstbuflen *= 2;
32 tmphstbuf = realloc (tmphstbuf, hstbuflen);
35 if (res != 0 || hp == NULL)
37 printf ("gethostbyname_r failed: %s (errno: %m)\n", strerror (res));
38 return 1;
41 printf ("Got: %s %s\n", hp->h_name,
42 inet_ntoa (*(struct in_addr *) hp->h_addr));
43 return 0;