Pull 25: Add Unix support to os.getversion() (wfgleper)
This commit is contained in:
parent
400ad0a0be
commit
5e48d05e3d
@ -89,6 +89,7 @@
|
||||
* Patch 3441850: Use debug.traceback() as error handler (Konstantin Tokarev)
|
||||
* 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)
|
||||
|
||||
|
||||
-------
|
||||
|
@ -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)
|
||||
|
@ -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__)
|
||||
|
Loading…
Reference in New Issue
Block a user