#include #include #include #ifdef HAVE_SYS_UTSNAME_H #include #endif /* this routine returns a name for the machine * it returns the empty string, if this info * not available (it never returns a NULL pointer) * * the name is stored in a static array and the pointer to this * array is returned. * */ char *G__machine_name(void) { static char name[128]; if (*name) return name; #if defined(HAVE_GETHOSTNAME) gethostname(name, sizeof(name)); name[sizeof(name) - 1] = 0; /* make sure NUL terminated */ #elif defined(HAVE_SYS_UTSNAME_H) { struct utsname attname; uname(&attname); strcpy(name, attname.nodename); } #elif strcpy(name, "unknown"); #endif return name; }