Loading...
Searching...
No Matches
mach_name.c
Go to the documentation of this file.
#include <unistd.h>
#include <grass/gis.h>
#include <grass/config.h>
#ifdef HAVE_SYS_UTSNAME_H
#include <sys/utsname.h>
#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.
*
*/
const char *G__machine_name(void)
{
static int initialized;
static char name[128];
if (G_is_initialized(&initialized))
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);
}
#else
strcpy(name, "unknown");
#endif
G_initialize_done(&initialized);
return name;
}
G_initialize_done
void G_initialize_done(int *p)
Definition counter.c:77
G_is_initialized
int G_is_initialized(int *p)
Definition counter.c:60
G__machine_name
const char * G__machine_name(void)
Definition mach_name.c:16
name
const char * name
Definition named_colr.c:6
strcpy
#define strcpy
Definition parson.c:66