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 */ 5 6 7 #include <sys/utsname.h> 8 9 #include <errno.h> 10 #include <stdio.h> 11 #include <string.h> 12 #include <unistd.h> 13 14 #include <OS.h> 15 16 #include <errno_private.h> 17 #include <system_revision.h> 18 19 20 int 21 uname(struct utsname *info) 22 { 23 cpu_topology_node_info root; 24 system_info systemInfo; 25 const char *platform; 26 const char *haikuRevision; 27 uint32_t count = 1; 28 status_t error; 29 30 if (!info) { 31 __set_errno(B_BAD_VALUE); 32 return -1; 33 } 34 35 get_system_info(&systemInfo); 36 37 strlcpy(info->sysname, "Haiku", sizeof(info->sysname)); 38 39 haikuRevision = __get_haiku_revision(); 40 if (haikuRevision[0] != '\0') 41 snprintf(info->version, sizeof(info->version), "%s ", haikuRevision); 42 else 43 info->version[0] = '\0'; 44 strlcat(info->version, systemInfo.kernel_build_date, sizeof(info->version)); 45 strlcat(info->version, " ", sizeof(info->version)); 46 strlcat(info->version, systemInfo.kernel_build_time, sizeof(info->version)); 47 snprintf(info->release, sizeof(info->release), "%" B_PRId64, 48 systemInfo.kernel_version); 49 50 error = get_cpu_topology_info(&root, &count); 51 if (error != B_OK || count < 1) 52 platform = "unknown"; 53 else { 54 switch (root.data.root.platform) { 55 case B_CPU_x86: 56 platform = "BePC"; 57 break; 58 case B_CPU_x86_64: 59 platform = "x86_64"; 60 break; 61 } 62 } 63 64 strlcpy(info->machine, platform, sizeof(info->machine)); 65 66 if (gethostname(info->nodename, sizeof(info->nodename)) != 0) 67 strlcpy(info->nodename, "unknown", sizeof(info->nodename)); 68 69 return 0; 70 } 71 72