1 |
/* A slightly more convenient wrapper for gethostname |
/* A slightly more convenient wrapper for gethostname |
2 |
|
|
3 |
Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc. |
Copyright (C) 1996, 1997, 2000, 2005 Free Software Foundation, Inc. |
4 |
|
|
5 |
Written by Miles Bader <miles@gnu.ai.mit.edu> |
Written by Miles Bader <miles@gnu.ai.mit.edu> |
6 |
|
|
36 |
#include <netinet/in.h> |
#include <netinet/in.h> |
37 |
#include <netdb.h> |
#include <netdb.h> |
38 |
|
|
|
#if __STDC__ |
|
|
# define VOID void |
|
|
#else |
|
|
# define VOID char |
|
|
#endif |
|
|
extern VOID *xrealloc __P((VOID *p, size_t n)); |
|
|
|
|
39 |
/* Return the name of the localhost. This is just a wrapper for gethostname, |
/* Return the name of the localhost. This is just a wrapper for gethostname, |
40 |
which takes care of allocating a big enough buffer, and caches the result |
which takes care of allocating a big enough buffer, and caches the result |
41 |
after the first call (so the result should be copied before modification). |
after the first call (so the result should be copied before modification). |
55 |
errno = 0; |
errno = 0; |
56 |
|
|
57 |
buf_len += 256; /* Initial guess */ |
buf_len += 256; /* Initial guess */ |
58 |
tmp = xrealloc (buf, buf_len); |
tmp = realloc (buf, buf_len); |
|
|
|
59 |
if (tmp == NULL) |
if (tmp == NULL) |
60 |
{ |
{ |
61 |
errno = ENOMEM; |
errno = ENOMEM; |