From: Jim Meyering Date: Mon, 2 May 1994 04:26:07 +0000 (+0000) Subject: . X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a38bc613499aee7806cecf6615af4ad2a09def61;p=pspp . --- diff --git a/lib/xgethostname.c b/lib/xgethostname.c new file mode 100644 index 0000000000..f00d7bd5f5 --- /dev/null +++ b/lib/xgethostname.c @@ -0,0 +1,29 @@ +#include + +int gethostname (); +char *xmalloc (); +char *xrealloc (); + +#define INITIAL_HOSTNAME_LENGTH 33 + +char * +xgethostname () +{ + char *hostname; + size_t size; + int err; + + size = INITIAL_HOSTNAME_LENGTH; + while (1) + { + hostname = xmalloc (size); + hostname[size - 1] = '\0'; + err = gethostname (hostname, size); + if (err || hostname[size - 1] == '\0') + break; + size *= 2; + hostname = xrealloc (hostname, size); + } + + return hostname; +}