This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH][BZ #2801] Fix gethostbyname_r example.
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: libc-alpha at sourceware dot org
- Date: Wed, 16 Oct 2013 18:21:18 +0200
- Subject: [PATCH][BZ #2801] Fix gethostbyname_r example.
- Authentication-results: sourceware.org; auth=none
Hi, here we fix example as we need to return allocated structure, not
pointer to local variable. OK to commit?
[BZ #2801]
* manual/socket.texi: Fix gethostbyname_r example.
diff --git a/manual/socket.texi b/manual/socket.texi
index 25c35c4..74917ea 100644
--- a/manual/socket.texi
+++ b/manual/socket.texi
@@ -1307,17 +1307,18 @@ Here's a small example:
struct hostent *
gethostname (char *host)
@{
- struct hostent hostbuf, *hp;
+ struct hostent *hostbuf, *hp;
size_t hstbuflen;
char *tmphstbuf;
int res;
int herr;
+ hostbuf = malloc (sizeof (struct hostent));
hstbuflen = 1024;
/* Allocate buffer, remember to free it to avoid memory leakage. */
tmphstbuf = malloc (hstbuflen);
- while ((res = gethostbyname_r (host, &hostbuf, tmphstbuf, hstbuflen,
+ while ((res = gethostbyname_r (host, hostbuf, tmphstbuf, hstbuflen,
&hp, &herr)) == ERANGE)
@{
/* Enlarge the buffer. */