From 3534b428629be185e096be99e3bd5fdfe32d5544 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 18 Sep 2014 18:55:44 +0000 Subject: initial commit with rc for skalibs-2.0.0.0 --- src/libstddjb/sagethostname.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/libstddjb/sagethostname.c (limited to 'src/libstddjb/sagethostname.c') diff --git a/src/libstddjb/sagethostname.c b/src/libstddjb/sagethostname.c new file mode 100644 index 0000000..500a95c --- /dev/null +++ b/src/libstddjb/sagethostname.c @@ -0,0 +1,27 @@ +/* ISC license. */ + +#include +#include +#include +#include + +int sagethostname (stralloc *sa) +{ + unsigned int n = 128 ; + int wasnull = !sa->s ; + + for (;;) + { + if (!stralloc_readyplus(sa, n)) goto err ; + sa->s[sa->len + n - 2] = 0 ; + if (gethostname(sa->s + sa->len, n) == -1) goto err ; + if (!sa->s[sa->len + n - 2]) break ; + n += 128 ; + } + sa->len += str_len(sa->s + sa->len) ; + return 0 ; + +err: + if (wasnull) stralloc_free(sa) ; + return -1 ; +} -- cgit v1.2.3