summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStig Bakken <ssb@php.net>2003-01-25 00:44:41 +0000
committerStig Bakken <ssb@php.net>2003-01-25 00:44:41 +0000
commitd19bd6f12c2cec7335829cfebd362cd1a83e5349 (patch)
tree8c5257a272f8f6b8949dbb68bc4426d8f4cd94d9
parenta46aac36ecfe482352d175e2e577ef6495b6b36c (diff)
downloadphp-git-d19bd6f12c2cec7335829cfebd362cd1a83e5349.tar.gz
* add glibc version detection for Linux
-rw-r--r--pear/OS/Guess.php53
1 files changed, 47 insertions, 6 deletions
diff --git a/pear/OS/Guess.php b/pear/OS/Guess.php
index 8e28e4f3be..97e665818e 100644
--- a/pear/OS/Guess.php
+++ b/pear/OS/Guess.php
@@ -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));
}