ws2_32: Move gethostname() to the Unix library.

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2021-08-04 21:20:43 -05:00 committed by Alexandre Julliard
parent 61b123fae9
commit c1c3691bed
3 changed files with 20 additions and 7 deletions

View File

@ -913,6 +913,7 @@ struct WS_hostent * WINAPI WS_gethostbyname( const char *name )
{
struct WS_hostent *host = NULL;
char hostname[100];
int ret;
TRACE( "%s\n", debugstr_a(name) );
@ -922,9 +923,9 @@ struct WS_hostent * WINAPI WS_gethostbyname( const char *name )
return NULL;
}
if (gethostname( hostname, 100 ) == -1)
if ((ret = unix_funcs->gethostname( hostname, 100 )))
{
SetLastError( WSAENOBUFS );
SetLastError( ret );
return NULL;
}
@ -973,7 +974,7 @@ struct WS_hostent * WINAPI WS_gethostbyname( const char *name )
int WINAPI WS_gethostname( char *name, int namelen )
{
char buf[256];
int len;
int len, ret;
TRACE( "name %p, len %d\n", name, namelen );
@ -983,9 +984,9 @@ int WINAPI WS_gethostname( char *name, int namelen )
return -1;
}
if (gethostname( buf, sizeof(buf) ) != 0)
if ((ret = unix_funcs->gethostname( buf, sizeof(buf) )))
{
SetLastError( sock_get_error( errno ) );
SetLastError( ret );
return -1;
}
@ -1009,6 +1010,7 @@ int WINAPI WS_gethostname( char *name, int namelen )
int WINAPI GetHostNameW( WCHAR *name, int namelen )
{
char buf[256];
int ret;
TRACE( "name %p, len %d\n", name, namelen );
@ -1018,9 +1020,9 @@ int WINAPI GetHostNameW( WCHAR *name, int namelen )
return -1;
}
if (gethostname( buf, sizeof(buf) ))
if ((ret = unix_funcs->gethostname( buf, sizeof(buf) )))
{
SetLastError( sock_get_error( errno ) );
SetLastError( ret );
return -1;
}

View File

@ -30,6 +30,7 @@
#include <errno.h>
#include <pthread.h>
#include <stdarg.h>
#include <unistd.h>
#include <sys/types.h>
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
@ -789,11 +790,20 @@ static int CDECL unix_gethostbyname( const char *name, struct WS_hostent *const
#endif
static int CDECL unix_gethostname( char *name, int len )
{
if (!gethostname( name, len ))
return 0;
return errno_from_unix( errno );
}
static const struct unix_funcs funcs =
{
unix_getaddrinfo,
unix_gethostbyaddr,
unix_gethostbyname,
unix_gethostname,
};
NTSTATUS CDECL __wine_init_unix_lib( HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out )

View File

@ -203,6 +203,7 @@ struct unix_funcs
int (CDECL *gethostbyaddr)( const void *addr, int len, int family,
struct WS(hostent) *host, unsigned int *size );
int (CDECL *gethostbyname)( const char *name, struct WS(hostent) *host, unsigned int *size );
int (CDECL *gethostname)( char *name, int len );
};
extern const struct unix_funcs *unix_funcs;