about summary refs log tree commit diff
path: root/converter/ppm/ppmtompeg/gethostname.c
blob: dedb3129526d754aa9e9234613c133ca9b72caa5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#define _DEFAULT_SOURCE /* New name for SVID & BSD source defines */
#define _XOPEN_SOURCE 500  /* Make sure strdup() is in string.h */
#define _BSD_SOURCE   /* Make sure strdup() is in string.h */

#include <string.h>
#include <errno.h>
#include <sys/utsname.h>

#include "pm.h"

#include "gethostname.h"

const char *
GetHostName(void) {
/*----------------------------------------------------------------------------
   Return the host name of this system.
-----------------------------------------------------------------------------*/
    struct utsname utsname;
    int rc;

    rc = uname(&utsname);

    if (rc < 0)
        pm_error("Unable to find out host name.  "
                 "uname() failed with errno %d (%s)", errno, strerror(errno));

    return strdup(utsname.nodename);
}