soc.2012.statscollector: 87cf6adb: Refactor code for detecting POSIX
sanket at soc.pidgin.im
sanket at soc.pidgin.im
Thu May 24 05:40:49 EDT 2012
----------------------------------------------------------------------
Revision: 87cf6adb2543d33a6280a554872c681897e82e6e
Parent: 7e8830de618c623ee27e5534743ffa8bb4ccefaf
Author: sanket at soc.pidgin.im
Date: 05/24/12 05:59:28
Branch: im.pidgin.soc.2012.statscollector
URL: http://d.pidgin.im/viewmtn/revision/info/87cf6adb2543d33a6280a554872c681897e82e6e
Changelog:
Refactor code for detecting POSIX
POSIX can be detected by presence of unistd.h and checking if
_POSIX_VERSION is defined. I have henced removed the components where I
was checking __APPLE__ and __LINUX__ etc separately (wherever possible).
Second change is to use ``uname -s'' as far as possible. This ensures that
we are using dynamic-run time information to detect platforms, which is a
good thing if cross-compiling of binaries is done!
Changes against parent 7e8830de618c623ee27e5534743ffa8bb4ccefaf
patched libpurple/plugins/statscollector.c
-------------- next part --------------
============================================================
--- libpurple/plugins/statscollector.c 95b6c16590dab258e425a0d071436aa3fd599a1c
+++ libpurple/plugins/statscollector.c 2362f2af78dc2b22d93f1a0679ee8b7fcde1bc48
@@ -18,14 +18,25 @@
#ifdef _WIN32
#include<windows.h>
+#endif
-#elif defined __APPLE__
+#ifdef __APPLE__
#include<CoreServices/CoreServices.h>
#include<sys/types.h>
#include<sys/sysctl.h>
-#include<sys/utsname.h>
-#include<dlfcn.h>
+#endif
+/* POSIX compliance is an issue that I have looked into some detail now
+ * It seems like presence of unistd.h and _POSIX_VERSION being defined
+ * confirms the presence of POSIX compliance. For this ofcourse we need
+ * to ensure that unistd.h is defined. As it is *already* a part of
+ * internal.h, we could directly go ahead with the testing if the
+ * system is POSIX or not
+ */
+
+#ifdef _POSIX_VERSION
+# include <sys/utsname.h>
+# include <dlfcn.h>
#endif
#define STATS_MAJOR_VERSION 1
@@ -133,20 +144,26 @@ get_os_32_64(){
int bit_size=-1;
xmlnode *bit_size_xml;
#ifdef _WIN32
+
BOOL bIsWow64;
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
LPFN_ISWOW64PROCESS fnIsWow64Process;
-#elif (defined __USE_POSIX) || (defined __APPLE__) /* What to use for APPLE */
+
+#elif defined _POSIX_VERSION
+
struct utsname os_utsname;
char *m_name;
+
#endif
bit_size_xml = xmlnode_new("os-bit");
#ifdef _WIN64
+
bit_size = 64;
#elif defined _WIN32
+
/* Check if we are running as wow64 process */
bIsWow64 = FALSE;
fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress( \
@@ -162,7 +179,8 @@ get_os_32_64(){
if(bIsWow64) bit_size= 64;
else bit_size = 32;
-#elif (defined __USE_POSIX) || (defined __APPLE__)
+#elif _POSIX_VERSION
+
/* Use uname to find kernel architecture and infer bit-size */
uname(&os_utsname);
m_name = os_utsname.machine;
@@ -175,6 +193,7 @@ get_os_32_64(){
|| !g_strcmp0(m_name, "amd64") || !g_strcmp0(m_name, "ppc64")) \
bit_size = 64;
else bit_size = 32;
+
#endif
xmlnode_insert_data(bit_size_xml, g_strdup_printf("%d", bit_size), -1);
@@ -190,23 +209,20 @@ get_arch(){
xmlnode *arch_xml;
char *arch_str;
-#if (defined __USE_POSIX) || (defined __APPLE__)
- struct utsname os_utsname;
-#elif defined _WIN32
+
+#ifdef _WIN32
SYSTEM_INFO sys_info;
typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD);
PGNSI pGNSI;
+#elif defined _POSIX_VERSION
+ struct utsname os_utsname;
#endif
arch_xml = xmlnode_new("arch");
-#if (defined __USE_POSIX) || (defined __APPLE__)
- uname(&os_utsname);
- arch_str = os_utsname.machine;
-
-#elif defined _WIN32
+#ifdef _WIN32
pGNSI = (PGNSI) GetProcAddress(
GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo");
@@ -228,6 +244,9 @@ get_arch(){
default:
arch_str = "UNKNOWN";
}
+#elif defined _POSIX_VERSION
+ uname(&os_utsname);
+ arch_str = os_utsname.machine;
#endif
xmlnode_set_attrib(arch_xml, "id", arch_str);
@@ -245,15 +264,14 @@ get_os_name(){
xmlnode *os_name_xml;
char *name_attrib;
+
#ifdef _WIN32
+
xmlnode *major_version, *minor_version;
OSVERSIONINFO osvi;
-#elif defined __USE_POSIX
- xmlnode *os_release, *os_version;
- struct utsname os_utsname;
-
#elif defined __APPLE__
+
int mib[2];
size_t length;
SInt32 major_version,minor_version,bug_fix_version;
@@ -275,17 +293,22 @@ get_os_name(){
sdl_library = dlopen("/System/Library/Frameworks/CoreServices.framework/CoreServices", RTLD_LAZY); // we assume standard location for framework
gestalt_ext = dlsym(sdl_library, "Gestalt");
-#endif
+#elif defined _POSIX_VERSION
+ xmlnode *os_release, *os_version;
+ struct utsname os_utsname;
+ uname(&os_utsname);
+#endif
+
os_name_xml = xmlnode_new("os-info");
#ifdef _WIN32
name_attrib = "windows";
-#elif defined __linux__
- name_attrib = "linux";
-#elif defined __APPLE__
- name_attrib = "apple";
+#elif defined _POSIX_VERSION
+ name_attrib = os_utsname.sysname;
+#else
+ name_attrib = "unknown";
#endif
xmlnode_set_attrib(os_name_xml, "id", name_attrib);
@@ -306,16 +329,6 @@ get_os_name(){
xmlnode_insert_child(os_name_xml, major_version);
xmlnode_insert_child(os_name_xml, minor_version);
-#elif defined __USE_POSIX
- uname(&os_utsname);
- os_release = xmlnode_new("release");
- os_version = xmlnode_new("version");
- xmlnode_insert_data(os_release, os_utsname.release, -1);
- xmlnode_insert_data(os_version, os_utsname.version, -1);
-
- xmlnode_insert_child(os_name_xml, os_release);
- xmlnode_insert_child(os_name_xml, os_version);
-
#elif defined __APPLE__
major_version_xml = xmlnode_new("major-version");
@@ -390,8 +403,20 @@ get_os_name(){
}
-#endif /* APPLE block */
+ /* APPLE block ends */
+#elif defined _POSIX_VERSION
+
+ os_release = xmlnode_new("release");
+ os_version = xmlnode_new("version");
+ xmlnode_insert_data(os_release, os_utsname.release, -1);
+ xmlnode_insert_data(os_version, os_utsname.version, -1);
+
+ xmlnode_insert_child(os_name_xml, os_release);
+ xmlnode_insert_child(os_name_xml, os_version);
+
+#endif
+
return os_name_xml;
}
More information about the Commits
mailing list