Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/premake-4.x.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/host
diff options
context:
space:
mode:
authorJason Perkins <starkos@industriousone.com>2012-11-12 19:51:25 +0400
committerJason Perkins <starkos@industriousone.com>2012-11-12 19:51:25 +0400
commit56bf6b23267a210d3f551acc32d21b937d2f470b (patch)
tree0d1e48d50c1fdbd8db70179d2dc96563734f9a75 /src/host
parentf3143022c5caeef991501d78ced0090c3852cf0b (diff)
Pull 25: Add Unix support to os.getversion() (wfgleper)
Diffstat (limited to 'src/host')
-rwxr-xr-xsrc/host/os_getversion.c60
-rwxr-xr-xsrc/host/premake.h2
2 files changed, 58 insertions, 4 deletions
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__)