Mercurial > hg > octave-nkf > gnulib-hg
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
new file mode 100644 --- /dev/null +++ b/lib/xgethostname.c @@ -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; +}