]> granicus.if.org Git - php/commitdiff
* add glibc version detection for Linux
authorStig Bakken <ssb@php.net>
Sat, 25 Jan 2003 00:44:41 +0000 (00:44 +0000)
committerStig Bakken <ssb@php.net>
Sat, 25 Jan 2003 00:44:41 +0000 (00:44 +0000)
pear/OS/Guess.php

index 8e28e4f3be13327786a58a684c7d11675dd0fdcd..97e665818e46acd4568201c7b4f4a01dcbf3a3af 100644 (file)
@@ -106,13 +106,14 @@ class OS_Guess
         if ($uname === null) {
             $uname = php_uname();
         }
-        $parts = preg_split('/\s+/', trim($uname));
+        $parts = split('[[:space:]]+', trim($uname));
         $n = count($parts);
 
         $release = $machine = $cpu = '';
         $sysname = $parts[0];
         $nodename = $parts[1];
         $cpu = $parts[$n-1];
+        $extra = '';
         if ($cpu == 'unknown') {
             $cpu = $parts[$n-2];
         }
@@ -124,8 +125,13 @@ class OS_Guess
             case 'Windows':
                 $release = $parts[3];
                 break;
+            case 'Linux':
+                $extra = $this->_detectGlibcVersion();
+                // use only the first two digits from the kernel version
+                $release = ereg_replace('^([[:digit:]]+\.[[:digit:]]+).*', '\1', $parts[2]);
+                break;
             default:
-                $release = preg_replace('/-.*/', '', $parts[2]);
+                $release = ereg_replace('-.*', '', $parts[2]);
                 break;
         }
 
@@ -138,13 +144,48 @@ class OS_Guess
         if (isset($cpumap[$cpu])) {
             $cpu = $cpumap[$cpu];
         }
-        $extra = '';
         return array($sysname, $release, $cpu, $extra, $nodename);
     }
 
+    function _detectGlibcVersion()
+    {
+        // Use glibc's <features.h> header file to
+        // get major and minor version number:
+        include_once "System.php";
+        $tmpfile = System::mktemp("glibctest");
+        $fp = fopen($tmpfile, "w");
+        fwrite($fp, "#include <features.h>\n__GLIBC__ __GLIBC_MINOR__\n");
+        fclose($fp);
+        $cpp = popen("/usr/bin/cpp $tmpfile", "r");
+        $major = $minor = 0;
+        while ($line = fgets($cpp, 1024)) {
+            if ($line{0} == '#') {
+                continue;
+            }
+            if (list($major, $minor) = explode(' ', trim($line))) {
+                break;
+            }
+        }
+        pclose($cpp);
+        unlink($tmpfile);
+        if (!($major && $minor) && file_exists('/lib/libc.so.6')) {
+            // Let's try reading the libc.so.6 symlink
+            if (ereg('^libc-([.*])\.so$', basename(readlink('/lib/libc.so.6')), $matches)) {
+                list($major, $minor) = explode('.', $matches);
+            }
+        }
+        if (!($major && $minor)) {
+            return '';
+        }
+        return "glibc{$major}.{$minor}";
+    }
+
     function getSignature()
     {
-        return "{$this->sysname}-{$this->release}-{$this->cpu}";
+        if (empty($this->extra)) {
+            return "{$this->sysname}-{$this->release}-{$this->cpu}";
+        }
+        return "{$this->sysname}-{$this->release}-{$this->cpu}-{$this->extra}";
     }
 
     function getSysname()
@@ -199,8 +240,8 @@ class OS_Guess
     function _matchFragment($fragment, $value)
     {
         if (strcspn($fragment, '*?') < strlen($fragment)) {
-            $preg = '/^' . str_replace(array('*', '?', '/'), array('.*', '.', '\\/'), $fragment) . '$/i';
-            return preg_match($preg, $value);
+            $reg = '^' . str_replace(array('*', '?', '/'), array('.*', '.', '\\/'), $fragment) . '$';
+            return eregi($preg, $value);
         }
         return ($fragment == '*' || !strcasecmp($fragment, $value));
     }