changeset 213:468db44d4c45

.
author Jim Meyering <jim@meyering.net>
date Mon, 02 May 1994 04:26:07 +0000
parents 8bc57d4e2dd4
children 64f3630c01ad
files lib/xgethostname.c
diffstat 1 files changed, 29 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/xgethostname.c	Mon May 02 04:26:07 1994 +0000
@@ -0,0 +1,29 @@
+#include <sys/types.h>
+
+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;
+}