[gethostbyname] Set appropriate error code

Rein Klazes rklazes at xs4all.nl
Wed Sep 3 14:34:47 CDT 2003

On Wed, 3 Sep 2003 18:20:56 +0200, you wrote:

> Changelog:
>   - Set appropriate error code for gethostbyname and WSAAsyncGetHostByName
>   - Restore NULL name/aq->host_name to NULL at the end of each function respectively
> Stephan
>                              aq->host_name = buf;
>                              if( gethostname( buf, 100) == -1) {
> -                                fail = WSAENOBUFS; /* appropriate ? */
> +                                fail = (errno == EINVAL) ? WSAEFAULT : wsaErrno();

Explanation why I arrived at WSAENOBUFS as appropriate value..

(Remember it is used as the error value for the windows code calling
gethostbyname(), not gethostname();)

- glibc documentation as I read it indicates that in this case the only
way gethostname() may fail is an insufficient bufferlength. Clearly
invalid name pointer or negative length do not apply.

- WSAEFAULT means (by Microsoft):
"The system detected an invalid pointer address in attempting to use a
pointer argument in a call"
At the vary least this will confuse somebody that does
gethostbyname(NULL), thinking it is the null pointer that is causing
this error. This is the one error code that I did not want to return,
that is why I cannot use the wsaErrno functions.

But perhaps you have found another cause where gethostname() will fail? 

> +    if (name==buf) name=NULL;
>      return retval;

name is an argument, passed by value. Destroyed as the function returns.
No need to restore.

Rein Klazes
rklazes at xs4all.nl

More information about the wine-devel mailing list