GRASS Programmer's Manual 6.4.1(2011)
mach_name.c
Go to the documentation of this file.
00001 #include <unistd.h>
00002 #include <grass/gis.h>
00003 /* this routine returns a name for the machine
00004  * it returns the empty string, if this info
00005  * not available (it never returns a NULL pointer)
00006  *
00007  * the name is stored in a static array and the pointer to this
00008  * array is returned.
00009  *
00010  * the contents of this array are reset upon each call
00011  *
00012  */
00013 
00014 #include <grass/config.h>
00015 
00016 #ifndef HAVE_GETHOSTNAME
00017 #ifdef HAVE_SYS_UTSNAME_H
00018 #include <sys/utsname.h>
00019 static struct utsname attname;
00020 #endif
00021 #endif
00022 
00023 char *G__machine_name(void)
00024 {
00025     static char name[128];
00026 
00027     *name = 0;
00028 
00029 #ifdef HAVE_GETHOSTNAME
00030     gethostname(name, sizeof(name));
00031     name[sizeof(name) - 1] = 0; /* make sure null terminated */
00032 #else
00033 #ifdef HAVE_SYS_UTSNAME_H
00034     uname(&attname);
00035     strcpy(name, attname.nodename);
00036 #endif
00037 #endif
00038 
00039     return (name);
00040 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines