stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r554430 - /incubator/stdcxx/trunk/etc/config/src/UNAME.cpp
Date Sun, 08 Jul 2007 20:22:36 GMT
Author: sebor
Date: Sun Jul  8 13:22:35 2007
New Revision: 554430

URL: http://svn.apache.org/viewvc?view=rev&rev=554430
Log:
2007-07-08  Martin Sebor  <sebor@roguewave.com>

	* UNAME.cpp (print_os_version): Factored OS-specific code from main
	into here.
	(print_linux_release): New function to determine the release of Linux
	from /etc/xxx-release and #define the _RWSTD_LINUX_RELEASE macro.

Modified:
    incubator/stdcxx/trunk/etc/config/src/UNAME.cpp

Modified: incubator/stdcxx/trunk/etc/config/src/UNAME.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/etc/config/src/UNAME.cpp?view=diff&rev=554430&r1=554429&r2=554430
==============================================================================
--- incubator/stdcxx/trunk/etc/config/src/UNAME.cpp (original)
+++ incubator/stdcxx/trunk/etc/config/src/UNAME.cpp Sun Jul  8 13:22:35 2007
@@ -9,14 +9,35 @@
 #endif
 
 
-int compare (const char *a, const char *b)
+static int print_os_version ();
+
+
+int main ()
+{
+    return print_os_version ();
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static unsigned length (const char *s)
+{
+    unsigned len = 0;
+
+    while (*s++)
+        ++len;
+
+    return len;
+}
+
+
+static int compare (const char *a, const char *b)
 {
     for (; *a && *a == *b; ++a, ++b);
     return *a - *b;
 }
 
 
-char* capitalize (char *str)
+static char* capitalize (char *str)
 {
     static const char upper[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
     static const char lower[] = "abcdefghijklmnopqrstuvwxyz0123456789";
@@ -43,16 +64,80 @@
 }
 
 
+
 #define ISDIGIT(x)   ((x) >= '0' && (x) <= '9')
 
-int main ()
+
+#ifndef _WIN32
+
+
+static void print_linux_release ()
 {
-#if !defined (_WIN32) && !defined (_WIN64)
+    static const char* const files[] = {
+        // Debian
+ 	"/etc/debian_release",   // see also /etc/debian_version?
+        // Fedora
+ 	"/etc/fedora-release",
+        // Gentoo
+ 	"/etc/gentoo-release",
+        // Novell SUSE
+  	"/etc/SuSE-release",
+        // Red Hat
+ 	"/etc/redhat-release",   // see also /etc/redhat_version?
+        // Slackware
+ 	"/etc/slackware-release",   // see also /etc/slackware-version?
+        // Mandrake
+ 	"/etc/mandrake-release",
+        // Mandriva
+        "/etc/mandriva-release",
+        // MEPIS Linux
+        "/etc/mepis-release",
+        // Sun JDS
+ 	"/etc/sun-release",
+        // Solaris/SPARC
+ 	"/etc/release",
+        // Turbo Linux
+        "/etc/turbolinux-release",
+        // UnitedLinux
+ 	"/etc/UnitedLinux-release",
+        // Ubuntu
+ 	"/etc/lsb-release",
+        // Yellow Dog
+ 	"/etc/yellowdog-release",
+
+        ////////////////////////////////////////////////////
+        // Last entry must be 0
+        0
+    };
+
+    FILE *fp = 0;
+
+    for (unsigned i = 0; files [i]; ++i) {
+        fp = fopen (files [i], "r");
+        if (fp)
+            break;
+    }
 
+
+    char buffer [1024] = "(unknown release)";
+
+    if (fp) {
+        char *s = fgets (buffer, int (sizeof buffer), fp);
+        if (s)
+            buffer [length (s) - 1] = '\0';
+
+    }
+
+    printf ("#define _RWSTD_LINUX_RELEASE \"%s\"\n", buffer);
+}
+
+
+static int print_os_version ()
+{
     struct utsname uts;
 
     if (0 > uname (&uts))
-        return 0;
+        return 1;
 
     printf ("#define _RWSTD_OS_%s\n", capitalize (uts.sysname));
 
@@ -99,8 +184,21 @@
 
     printf ("#define _RWSTD_OS_MICRO %lu\n", num);
 
-#else   // if defined (_WIN{32,64})
+    if (0 == compare ("LINUX", uts.sysname)) {
+
+        // determine Linux distribution
+        print_linux_release ();
+    }
+
+    return 0;
+}
+
 
+#else   // if defined (_WIN32)
+
+
+static int print_os_version ()
+{
     OSVERSIONINFO osinfo;
     osinfo.dwOSVersionInfoSize = sizeof osinfo;
 
@@ -110,7 +208,7 @@
     printf ("#define _RWSTD_OS_SYSNAME \"WINDOWS\"\n");
 
     if (!success)
-        return 0;
+        return 1;
 
     printf ("#define _RWSTD_OS_MAJOR %lu\n", osinfo.dwMajorVersion);
     printf ("#define _RWSTD_OS_MINOR %lu\n", osinfo.dwMinorVersion);
@@ -150,7 +248,7 @@
 
     printf ("#define _RWSTD_OS_VERSION \"%s\"\n", osinfo.szCSDVersion);
 
-#endif   // _WIN{32,64}
-
     return 0;
 }
+
+#endif   // _WIN32



Mime
View raw message