diff options
-rw-r--r-- | CHANGES.txt | 5 | ||||
-rwxr-xr-x | src/host/os_getversion.c | 60 | ||||
-rwxr-xr-x | src/host/premake.h | 2 |
3 files changed, 61 insertions, 6 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 003bc97..d743d91 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -62,8 +62,9 @@ * Patch 3367642: Add support for targetextension property to Xcode * Patch 3435716: Fix for PS3 config generation in VS2010 (Jake) * Patch 3441850: Use debug.traceback() as error handler (Konstantin Tokarev) -* Patch 3462994: Make flag values case-insensitive -* Patch 3466877: Removed -flat_namespace from Mac OS X flags +* Patch 3462994: Make flag values case-insensitive (Konstantin Tokarev) +* Patch 3466877: Removed -flat_namespace from Mac OS X flags (Konstantin Tokarev) +* Pull 25: Add Unix support to os.getversion() (wfgleper) ------- diff --git a/src/host/os_getversion.c b/src/host/os_getversion.c index 950372a..446848f 100755 --- a/src/host/os_getversion.c +++ b/src/host/os_getversion.c @@ -1,10 +1,11 @@ /** * \file os_getversioninfo.c * \brief Retrieve operating system version information. - * \author Copyright (c) 2011 Jason Perkins and the Premake project + * \author Copyright (c) 2011-2012 Jason Perkins and the Premake project */ #include "premake.h" +#include <stdlib.h> struct OsVersionInfo { @@ -12,13 +13,15 @@ struct OsVersionInfo int minorversion; int revision; const char* description; -} ; + int isalloc; +}; static void getversion(struct OsVersionInfo* info); + int os_getversion(lua_State* L) { - struct OsVersionInfo info; + struct OsVersionInfo info = {0}; getversion(&info); lua_newtable(L); @@ -39,6 +42,10 @@ int os_getversion(lua_State* L) lua_pushstring(L, info.description); lua_settable(L, -3); + if (info.isalloc) { + free((void*)info.description); + } + return 1; } @@ -174,6 +181,53 @@ void getversion(struct OsVersionInfo* info) /*************************************************************/ +#elif defined(PLATFORM_BSD) || defined(PLATFORM_LINUX) || defined(PLATFORM_SOLARIS) + +#include <string.h> +#include <sys/utsname.h> + +void getversion(struct OsVersionInfo* info) +{ + struct utsname u; + char* ver; + + info->majorversion = 0; + info->minorversion = 0; + info->revision = 0; + + if (uname(&u)) + { + // error + info->description = PLATFORM_STRING; + return; + } + +#if __GLIBC__ + // When using glibc, info->description gets set to u.sysname, + // but it isn't passed out of this function, so we need to copy + // the string. + info->description = malloc(strlen(u.sysname) + 1); + strcpy((char*)info->description, u.sysname); + info->isalloc = 1; +#else + info->description = u.sysname; +#endif + + if ((ver = strtok(u.release, ".-")) != NULL) + { + info->majorversion = atoi(ver); + // continue parsing from the previous position + if ((ver = strtok(NULL, ".-")) != NULL) + { + info->minorversion = atoi(ver); + if ((ver = strtok(NULL, ".-")) != NULL) + info->revision = atoi(ver); + } + } +} + +/*************************************************************/ + #else void getversion(struct OsVersionInfo* info) diff --git a/src/host/premake.h b/src/host/premake.h index a374780..1e69a89 100755 --- a/src/host/premake.h +++ b/src/host/premake.h @@ -15,7 +15,7 @@ #if defined(__linux__) #define PLATFORM_LINUX (1) #define PLATFORM_STRING "linux" -#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) +#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) #define PLATFORM_BSD (1) #define PLATFORM_STRING "bsd" #elif defined(__APPLE__) && defined(__MACH__) |