~ubuntu-branches/ubuntu/feisty/elinks/feisty-updates

« back to all changes in this revision

Viewing changes to src/osdep/sysname.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2006-06-30 08:57:43 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060630085743-l81fgbw9dehvl1ds
Tags: 0.11.1-1ubuntu1
* Merge to Debian unstable.
* Removed gnutls12 porting, this is upstream now.
* Only Ubuntu changes left:
  - Killed type-handling.
  - Add X-Ubuntu-Gettext-Domain to .desktop files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Get system name */
 
2
 
 
3
#ifdef HAVE_CONFIG_H
 
4
#include "config.h"
 
5
#endif
 
6
 
 
7
#include <stdio.h>
 
8
#include <string.h>
 
9
#ifdef HAVE_SYS_UTSNAME_H
 
10
#include <sys/utsname.h>
 
11
#endif
 
12
 
 
13
#include "elinks.h"
 
14
 
 
15
#include "osdep/sysname.h"
 
16
#include "util/memory.h"
 
17
#include "util/string.h"
 
18
 
 
19
 
 
20
unsigned char system_name[MAX_STR_LEN];
 
21
 
 
22
#ifdef HAVE_POPEN
 
23
static int
 
24
got_it_from_uname_command(void)
 
25
{
 
26
        FILE *f;
 
27
        unsigned char *p;
 
28
 
 
29
        f = popen("uname -srm", "r");
 
30
        if (!f) return 0;
 
31
 
 
32
        if (fread(system_name, 1, sizeof(system_name) - 1, f) <= 0) {
 
33
                pclose(f);
 
34
                return 0;
 
35
        }
 
36
 
 
37
        pclose(f);
 
38
 
 
39
        system_name[MAX_STR_LEN - 1] = '\0'; /* Safer. */
 
40
        p = system_name;
 
41
        while (*p >= ' ') p++;
 
42
        *p = '\0';
 
43
 
 
44
        if (system_name[0])
 
45
                return 1;
 
46
 
 
47
        return 0;
 
48
}
 
49
#else
 
50
#define got_it_from_uname_command() 0
 
51
#endif
 
52
 
 
53
void
 
54
get_system_name(void)
 
55
{
 
56
#if defined(HAVE_SYS_UTSNAME_H) && defined(HAVE_UNAME)
 
57
        struct utsname name;
 
58
 
 
59
        if (!uname(&name)) {
 
60
                snprintf(system_name, sizeof(system_name),
 
61
                         "%s %s %s", name.sysname, name.release, name.machine);
 
62
                return;
 
63
        }
 
64
#endif
 
65
 
 
66
        if (got_it_from_uname_command()) return;
 
67
 
 
68
        safe_strncpy(system_name, SYSTEM_NAME, sizeof(system_name));
 
69
}