mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-10 09:58:01 +00:00
Remove reallocation loop in Windows get_hostname.
I've just noticed that the MSDN docs for WinSock gethostname() guarantee that a size-256 buffer is large enough. That seems a lot simpler than the previous faff.
This commit is contained in:
parent
59c8df4130
commit
a432943d19
@ -1816,18 +1816,10 @@ int net_service_lookup(char *service)
|
|||||||
|
|
||||||
char *get_hostname(void)
|
char *get_hostname(void)
|
||||||
{
|
{
|
||||||
int len = 128;
|
char hostbuf[256]; /* MSDN docs for gethostname() promise this is enough */
|
||||||
char *hostname = NULL;
|
if (p_gethostname(hostbuf, sizeof(hostbuf)) < 0)
|
||||||
do {
|
return NULL;
|
||||||
len *= 2;
|
return dupstr(hostbuf);
|
||||||
hostname = sresize(hostname, len, char);
|
|
||||||
if (p_gethostname(hostname, len) < 0) {
|
|
||||||
sfree(hostname);
|
|
||||||
hostname = NULL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while (strlen(hostname) >= (size_t)(len-1));
|
|
||||||
return hostname;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SockAddr *platform_get_x11_unix_address(const char *display, int displaynum,
|
SockAddr *platform_get_x11_unix_address(const char *display, int displaynum,
|
||||||
|
Loading…
Reference in New Issue
Block a user