1 /* Copyright 2002, Red Hat Inc. */ 2 3 #include <errno.h> 4 #include <string.h> 5 #include <unistd.h> 6 #include <sys/utsname.h> 7 #include <machine/weakalias.h> 8 9 int __gethostname(char * name,size_t len)10__gethostname (char *name, size_t len) 11 { 12 struct utsname nodebuf; 13 size_t nodelen; 14 15 if (uname (&nodebuf)) 16 return -1; 17 18 nodelen = strlen (nodebuf.nodename) + 1; 19 if (len < nodelen) 20 memcpy (name, nodebuf.nodename, len); 21 else 22 memcpy (name, nodebuf.nodename, nodelen); 23 24 if (nodelen > len) 25 { 26 errno = ENAMETOOLONG; 27 return -1; 28 } 29 return 0; 30 } 31 weak_alias(__gethostname, gethostname) 32