rem: hostname[k] = '\0'; err = gethostname (hostname, size); if (err >= 0 && hostname[k] == '\0') break; else if (err < 0 && errno != ENAMETOOLONG && errno != 0) error (EXIT_FAILURE, errno, "gethostname"); size *= 2; hostname = xrealloc (hostname, size + 1);
add: if (gethostname (hostname, size_1) == 0) { if (! hostname[size_1 - 1]) break; } else if (errno != 0 && errno != ENAMETOOLONG && errno != EINVAL) { int saved_errno = errno; free (hostname); errno = saved_errno; return NULL; }
context: xgethostname (){  char *hostname;  size_t size;  size = INITIAL_HOSTNAME_LENGTH;  /* Use size + 1 here rather than size to work around the bug     in SunOS5.5's gethostname whereby it NUL-terminates HOSTNAME     even when the name is longer than the supplied buffer.  */  hostname = xmalloc (size + 1);  while (1)    {      int k = size - 1;      int err;      errno = 0;      hostname[k] = '\0';      err = gethostname (hostname, size);      if (err >= 0 && hostname[k] == '\0')	break;      else if (err < 0 && errno != ENAMETOOLONG && errno != 0)	error (EXIT_FAILURE, errno, "gethostname");      size *= 2;      hostname = xrealloc (hostname, size + 1);    }  return hostname;}