xref: /haiku/src/system/libroot/posix/sys/uname.c (revision 93a78ecaa45114d68952d08c4778f073515102f2)
1 /*
2  * Copyright 2004, Jérôme Duval jerome.duval@free.fr. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <OS.h>
8 
9 #include <sys/utsname.h>
10 #include <errno.h>
11 #include <stdio.h>
12 #include <string.h>
13 
14 
15 // Haiku SVN revision. Will be set when copying libroot.so to the image.
16 // Lives in a separate section so that it can easily be found.
17 static uint32 sHaikuRevision __attribute__((section("_haiku_revision")));
18 static uint32 sHaikuRevision = 0;
19 
20 
21 int
22 uname(struct utsname *info)
23 {
24 	system_info systemInfo;
25 	const char *platform;
26 
27 	if (!info) {
28 		errno = B_BAD_VALUE;
29 		return -1;
30 	}
31 
32 	get_system_info(&systemInfo);
33 
34 	strlcpy(info->sysname, "Haiku", sizeof(info->sysname));
35 
36 	info->version[0] = '\0';
37 	if (sHaikuRevision) {
38 		snprintf(info->version, sizeof(info->version), "r%ld ",
39 			sHaikuRevision);
40 	}
41 	strlcat(info->version, systemInfo.kernel_build_date, sizeof(info->version));
42 	strlcat(info->version, " ", sizeof(info->version));
43 	strlcat(info->version, systemInfo.kernel_build_time, sizeof(info->version));
44 	snprintf(info->release, sizeof(info->release), "%lld",
45 		systemInfo.kernel_version);
46 
47 	// TODO: make this better
48 	switch (systemInfo.platform_type) {
49 		case B_BEBOX_PLATFORM:
50 			platform = "BeBox";
51 			break;
52 		case B_MAC_PLATFORM:
53 			platform = "BeMac";
54 			break;
55 		case B_AT_CLONE_PLATFORM:
56 			platform = "BePC";
57 			break;
58 		default:
59 			platform = "unknown";
60 			break;
61 	}
62 	strlcpy(info->machine, platform, sizeof(info->machine));
63 
64 	// TODO fill nodename field when we have hostname info
65 	strlcpy(info->nodename, "unknown", sizeof(info->nodename));
66 
67 	return 0;
68 }
69 
70