From 0ea5db4f1f55e55942f6afd0e4e69ceb2163ed25 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Wed, 30 Jun 1999 17:16:08 +0000 Subject: Update. 1999-06-28 Andreas Jaeger * inet/rcmd.c (__icheckhost): Test for gethostbyname_r result correctly. 1999-06-25 Andreas Jaeger * manual/arith.texi (System V Number Conversion): Fix the description which confused pointer and value to pointer. Reported by Andries.Brouwer@cwi.nl. 1999-06-28 Andreas Jaeger * pwd/getpw.c (__getpw): Check for NULL result pointer. 1999-06-29 Andreas Jaeger * manual/users.texi (Lookup User): Document POSIX return semantics for getpwuid_r and getgrgid_r. * manual/socket.texi (Host Names): Document that the result pointer is null in case of error or host not found and fix a typo. Give a small example. --- manual/socket.texi | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) (limited to 'manual/socket.texi') diff --git a/manual/socket.texi b/manual/socket.texi index b9102c6..d77e556 100644 --- a/manual/socket.texi +++ b/manual/socket.texi @@ -1284,13 +1284,42 @@ pointer and the size of the buffer in the @var{buf} and @var{buflen} parameters. A pointer to the buffer, in which the result is stored, is available in -@code{*@var{result}} after the function call successfully returned. -Success is signalled by a zero return value. If the function failed the -return value is an error number. In addition to the errors defined for -@code{gethostbyname} it can also be @code{ERANGE}. In this case the -call should be repeated with a larger buffer. Additional error -information is not stored in the global variable @code{h_errno} but -instead in the object pointed to by @var{h_errnop}. +@code{*@var{result}} after the function call successfully returned. If +an error occurs or if no entry is found, the pointer @code{*var{result} +is a null pointer. Success is signalled by a zero return value. If the +function failed the return value is an error number. In addition to the +errors defined for @code{gethostbyname} it can also be @code{ERANGE}. +In this case the call should be repeated with a larger buffer. +Additional error information is not stored in the global variable +@code{h_errno} but instead in the object pointed to by @var{h_errnop}. + +Here's a small example: +@smallexample +struct hostent * +gethostname (char *host) +@{ + struct hostent hostbuf, *hp; + size_t hstbuflen; + char *tmphstbuf; + int res; + int herr; + + hstbuflen = 1024; + tmphstbuf = malloc (hstbuflen); + + while ((res = gethostbyname_r (host, &hostbuf, tmphstbuf, hstbuflen, + &hp, &herr)) == ERANGE) + @{ + /* Enlarge the buffer. */ + hstbuflen *= 2; + tmphstbuf = realloc (tmphstbuf, hstbuflen); + @} + /* Check for errors. */ + if (res || hp == NULL) + return NULL; + return hp->h_name; +@} +@end smallexample @end deftypefun @comment netdb.h @@ -1314,7 +1343,7 @@ Internet address, use @code{AF_INET6}. Similar to the @code{gethostbyname_r} function, the caller must provide buffers for the result and memory used internally. In case of success -the funciton returns zero. Otherwise the value is an error number where +the function returns zero. Otherwise the value is an error number where @code{ERANGE} has the special meaning that the caller-provided buffer is too small. @end deftypefun -- cgit v1.1