2002-05-25 02:50:29 +08:00
|
|
|
/* Copyright 2002, Red Hat Inc. */
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/utsname.h>
|
2002-06-25 05:46:06 +08:00
|
|
|
#include <machine/weakalias.h>
|
2002-05-25 02:50:29 +08:00
|
|
|
|
|
|
|
int
|
2002-06-25 05:46:06 +08:00
|
|
|
__gethostname (char *name, size_t len)
|
2002-05-25 02:50:29 +08:00
|
|
|
{
|
|
|
|
struct utsname nodebuf;
|
|
|
|
size_t nodelen;
|
|
|
|
|
|
|
|
if (uname (&nodebuf))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
nodelen = strlen (nodebuf.nodename) + 1;
|
|
|
|
if (len < nodelen)
|
|
|
|
memcpy (name, nodebuf.nodename, len);
|
|
|
|
else
|
|
|
|
memcpy (name, nodebuf.nodename, nodelen);
|
|
|
|
|
|
|
|
if (nodelen > len)
|
|
|
|
{
|
|
|
|
errno = ENAMETOOLONG;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2002-06-25 05:46:06 +08:00
|
|
|
weak_alias(__gethostname, gethostname)
|