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 system_info systemInfo; 24 const char *platform; 25 const char *haikuRevision; 26 27 if (!info) { 28 __set_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 haikuRevision = __get_haiku_revision(); 37 if (haikuRevision[0] != '\0') 38 snprintf(info->version, sizeof(info->version), "%s ", haikuRevision); 39 else 40 info->version[0] = '\0'; 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), "%" B_PRId64, 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 case B_64_BIT_PC_PLATFORM: 59 platform = "x86_64"; 60 break; 61 default: 62 platform = "unknown"; 63 break; 64 } 65 strlcpy(info->machine, platform, sizeof(info->machine)); 66 67 if (gethostname(info->nodename, sizeof(info->nodename)) != 0) 68 strlcpy(info->nodename, "unknown", sizeof(info->nodename)); 69 70 return 0; 71 } 72 73