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 17 // Haiku SVN revision. Will be set when copying libroot.so to the image. 18 // Lives in a separate section so that it can easily be found. 19 static uint32 sHaikuRevision __attribute__((section("_haiku_revision"))); 20 static uint32 sHaikuRevision = 0; 21 22 23 int 24 uname(struct utsname *info) 25 { 26 system_info systemInfo; 27 const char *platform; 28 29 if (!info) { 30 errno = B_BAD_VALUE; 31 return -1; 32 } 33 34 get_system_info(&systemInfo); 35 36 strlcpy(info->sysname, "Haiku", sizeof(info->sysname)); 37 38 info->version[0] = '\0'; 39 if (sHaikuRevision) { 40 snprintf(info->version, sizeof(info->version), "r%ld ", 41 sHaikuRevision); 42 } 43 strlcat(info->version, systemInfo.kernel_build_date, sizeof(info->version)); 44 strlcat(info->version, " ", sizeof(info->version)); 45 strlcat(info->version, systemInfo.kernel_build_time, sizeof(info->version)); 46 snprintf(info->release, sizeof(info->release), "%lld", 47 systemInfo.kernel_version); 48 49 // TODO: make this better 50 switch (systemInfo.platform_type) { 51 case B_BEBOX_PLATFORM: 52 platform = "BeBox"; 53 break; 54 case B_MAC_PLATFORM: 55 platform = "BeMac"; 56 break; 57 case B_AT_CLONE_PLATFORM: 58 platform = "BePC"; 59 break; 60 default: 61 platform = "unknown"; 62 break; 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