~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/gis/mach_name.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include <unistd.h>
2
2
#include <grass/gis.h>
 
3
#include <grass/config.h>
 
4
#ifdef HAVE_SYS_UTSNAME_H
 
5
#include <sys/utsname.h>
 
6
#endif
 
7
 
3
8
/* this routine returns a name for the machine
4
9
 * it returns the empty string, if this info
5
10
 * not available (it never returns a NULL pointer)
7
12
 * the name is stored in a static array and the pointer to this
8
13
 * array is returned.
9
14
 *
10
 
 * the contents of this array are reset upon each call
11
 
 *
12
15
 */
13
16
 
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)
 
17
const char *G__machine_name(void)
24
18
{
 
19
    static int initialized;
25
20
    static char name[128];
26
21
 
27
 
    *name = 0;
 
22
    if (G_is_initialized(&initialized))
 
23
        return name;
28
24
 
29
 
#ifdef HAVE_GETHOSTNAME
 
25
#if defined(HAVE_GETHOSTNAME)
30
26
    gethostname(name, sizeof(name));
31
 
    name[sizeof(name) - 1] = 0; /* make sure null terminated */
 
27
    name[sizeof(name) - 1] = 0; /* make sure NUL terminated */
 
28
#elif defined(HAVE_SYS_UTSNAME_H)
 
29
    {
 
30
        struct utsname attname;
 
31
        uname(&attname);
 
32
        strcpy(name, attname.nodename);
 
33
    }
32
34
#else
33
 
#ifdef HAVE_SYS_UTSNAME_H
34
 
    uname(&attname);
35
 
    strcpy(name, attname.nodename);
36
 
#endif
 
35
    strcpy(name, "unknown");
37
36
#endif
38
37
 
39
 
    return (name);
 
38
    G_initialize_done(&initialized);
 
39
    return name;
40
40
}