/* Copyright 2002, Red Hat Inc. */ #include #include #include #include int gethostname (char *name, size_t len) { 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; }