summaryrefslogtreecommitdiff
path: root/lib/xgethostname.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/xgethostname.c')
-rw-r--r--lib/xgethostname.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/xgethostname.c b/lib/xgethostname.c
index 86408e775..9973b45be 100644
--- a/lib/xgethostname.c
+++ b/lib/xgethostname.c
@@ -46,12 +46,12 @@ xgethostname ()
int err;
size = INITIAL_HOSTNAME_LENGTH;
+ hostname = xmalloc (size);
while (1)
{
- hostname = xmalloc (size);
hostname[size - 1] = '\0';
err = gethostname (hostname, size);
- if (err || hostname[size - 1] == '\0')
+ if (err == 0 && hostname[size - 1] == '\0')
break;
size *= 2;
hostname = xrealloc (hostname, size);