Compilation fix on Mingw32.
[elinks.git] / src / osdep / sysname.c
blob31d829d7212ccf586e75a679117b8c1b828697b5
1 /* Get system name */
3 #ifdef HAVE_CONFIG_H
4 #include "config.h"
5 #endif
7 #include <stdio.h>
8 #include <string.h>
9 #ifdef HAVE_SYS_UTSNAME_H
10 #include <sys/utsname.h>
11 #endif
13 #include "elinks.h"
15 #include "osdep/sysname.h"
16 #include "util/memory.h"
17 #include "util/string.h"
20 unsigned char system_name[MAX_STR_LEN];
22 #ifdef HAVE_POPEN
23 static int
24 got_it_from_uname_command(void)
26 FILE *f;
27 unsigned char *p;
29 f = popen("uname -srm", "r");
30 if (!f) return 0;
32 if (fread(system_name, 1, sizeof(system_name) - 1, f) <= 0) {
33 pclose(f);
34 return 0;
37 pclose(f);
39 system_name[MAX_STR_LEN - 1] = '\0'; /* Safer. */
40 p = system_name;
41 while (*p >= ' ') p++;
42 *p = '\0';
44 if (system_name[0])
45 return 1;
47 return 0;
49 #else
50 #define got_it_from_uname_command() 0
51 #endif
53 void
54 get_system_name(void)
56 #if defined(HAVE_SYS_UTSNAME_H) && defined(HAVE_UNAME)
57 struct utsname name;
59 if (!uname(&name)) {
60 snprintf(system_name, sizeof(system_name),
61 "%s %s %s", name.sysname, name.release, name.machine);
62 return;
64 #endif
66 if (got_it_from_uname_command()) return;
68 safe_strncpy(system_name, SYSTEM_NAME, sizeof(system_name));