GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
mach_name.c
Go to the documentation of this file.
1 #include <unistd.h>
2 #include <grass/gis.h>
3 /* this routine returns a name for the machine
4  * it returns the empty string, if this info
5  * not available (it never returns a NULL pointer)
6  *
7  * the name is stored in a static array and the pointer to this
8  * array is returned.
9  *
10  * the contents of this array are reset upon each call
11  *
12  */
13 
14 #include <grass/config.h>
15 
16 #ifndef HAVE_GETHOSTNAME
17 #ifdef HAVE_SYS_UTSNAME_H
18 #include <sys/utsname.h>
19 static struct utsname attname;
20 #endif
21 #endif
22 
23 char *G__machine_name(void)
24 {
25  static char name[128];
26 
27  *name = 0;
28 
29 #ifdef HAVE_GETHOSTNAME
30  gethostname(name, sizeof(name));
31  name[sizeof(name) - 1] = 0; /* make sure null terminated */
32 #else
33 #ifdef HAVE_SYS_UTSNAME_H
34  uname(&attname);
35  strcpy(name, attname.nodename);
36 #endif
37 #endif
38 
39  return (name);
40 }
string name
Definition: render.py:1314
char * G__machine_name(void)
Definition: mach_name.c:23