summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/xalloc.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/include/xalloc.h b/include/xalloc.h
index 1704259bc..7b685e718 100644
--- a/include/xalloc.h
+++ b/include/xalloc.h
@@ -75,4 +75,19 @@ static inline int __attribute__ ((__format__(printf, 2, 3)))
err(XALLOC_EXIT_CODE, "cannot allocate string");
return ret;
}
+
+
+static inline char *xgethostname(void)
+{
+ char *name;
+ size_t sz = get_hostname_max() + 1;
+
+ name = xmalloc(sizeof(char) * sz);
+ if (gethostname(name, sz) != 0)
+ return NULL;
+
+ name[sz - 1] = '\0';
+ return name;
+}
+
#endif