vfs: check userland buffers before reading them.
[haiku.git] / src / system / libroot / posix / sys / uname.c
blobe7f02b68d804c413b66fd5fb401f70a65e86f84b
1 /*
2 * Copyright 2004-2007, Jérôme Duval jerome.duval@free.fr. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
7 #include <sys/utsname.h>
9 #include <errno.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <unistd.h>
14 #include <OS.h>
15 #include <ByteOrder.h>
17 #include <errno_private.h>
18 #include <system_revision.h>
21 int
22 uname(struct utsname *info)
24 cpu_topology_node_info root;
25 system_info systemInfo;
26 const char *platform;
27 const char *haikuRevision;
28 uint32 count = 1;
29 status_t error;
31 if (!info) {
32 __set_errno(B_BAD_VALUE);
33 return -1;
36 get_system_info(&systemInfo);
38 strlcpy(info->sysname, "Haiku", sizeof(info->sysname));
40 haikuRevision = __get_haiku_revision();
41 if (haikuRevision[0] != '\0')
42 snprintf(info->version, sizeof(info->version), "%s ", haikuRevision);
43 else
44 info->version[0] = '\0';
45 strlcat(info->version, systemInfo.kernel_build_date, sizeof(info->version));
46 strlcat(info->version, " ", sizeof(info->version));
47 strlcat(info->version, systemInfo.kernel_build_time, sizeof(info->version));
48 snprintf(info->release, sizeof(info->release), "%" B_PRId64,
49 systemInfo.kernel_version);
51 error = get_cpu_topology_info(&root, &count);
52 if (error != B_OK || count < 1)
53 platform = "unknown";
54 else {
55 switch (root.data.root.platform) {
56 case B_CPU_x86:
57 platform = "BePC";
58 break;
59 case B_CPU_x86_64:
60 platform = "x86_64";
61 break;
62 case B_CPU_PPC:
63 platform = "ppc";
64 break;
65 case B_CPU_PPC_64:
66 platform = "ppc64";
67 break;
68 case B_CPU_M68K:
69 platform = "m68k";
70 break;
71 case B_CPU_ARM:
72 /* The minimal ARM version emulated by QEMU
73 * XXX: use armv6 (raspberry Pi)?
74 * XXX: should we really use B_HOST_IS_LENDIAN here?
75 * XXX: use real cpu version as on Linux?
76 * cf. http://git.qemu.org/?p=qemu.git;a=blob;f=linux-user/uname.c
78 #if B_HOST_IS_LENDIAN
79 platform = "armv5tel";
80 #else
81 platform = "armv5teb";
82 #endif
83 break;
84 case B_CPU_ARM_64:
85 platform = "aarch64";
86 break;
87 case B_CPU_ALPHA:
88 platform = "alpha";
89 break;
90 case B_CPU_MIPS:
91 platform = "mips";
92 break;
93 case B_CPU_SH:
94 platform = "sh4";
95 break;
96 case B_CPU_UNKNOWN:
97 default:
98 platform = "unknown";
99 break;
103 strlcpy(info->machine, platform, sizeof(info->machine));
105 if (gethostname(info->nodename, sizeof(info->nodename)) != 0)
106 strlcpy(info->nodename, "unknown", sizeof(info->nodename));
108 return 0;