112 static $sysmap = array(
116 static $cpumap = array(
121 if ($uname ===
null) {
122 $uname = php_uname();
124 $parts = preg_split(
'/\s+/', trim($uname));
132 if (
$cpu ==
'unknown') {
133 $cpu = $parts[$n - 2];
154 $release = preg_replace(
'/^([0-9]+\.[0-9]+).*/',
'\1', $parts[2]);
160 if (
$cpu ==
'Macintosh') {
161 if ($parts[$n - 2] ==
'Power') {
167 if (
$cpu ==
'Macintosh') {
168 if ($parts[$n - 2] ==
'Power') {
172 $release = preg_replace(
'/^([0-9]+\.[0-9]+).*/',
'\1', $parts[2]);
175 $release = preg_replace(
'/-.*/',
'', $parts[2]);
184 if (isset($cpumap[
$cpu])) {
192 static $glibc =
false;
193 if ($glibc !==
false) {
197 include_once
"System.php";
199 if (@is_link(
'/lib64/libc.so.6')) {
201 if (preg_match(
'/^libc-(.*)\.so$/', basename(readlink(
'/lib64/libc.so.6')), $matches)) {
202 list($major, $minor) = explode(
'.', $matches[1]);
204 }
else if (@is_link(
'/lib/libc.so.6')) {
206 if (preg_match(
'/^libc-(.*)\.so$/', basename(readlink(
'/lib/libc.so.6')), $matches)) {
207 list($major, $minor) = explode(
'.', $matches[1]);
212 if (!($major && $minor) &&
213 @file_exists(
'/usr/include/features.h') &&
214 @is_readable(
'/usr/include/features.h')) {
215 if (!@file_exists(
'/usr/bin/cpp') || !@is_executable(
'/usr/bin/cpp')) {
216 $features_file = fopen(
'/usr/include/features.h',
'rb');
217 while (!feof($features_file)) {
218 $line = fgets($features_file, 8192);
219 if (!$line || (strpos($line,
'#define') ===
false)) {
222 if (strpos($line,
'__GLIBC__')) {
224 $line = preg_split(
'/\s+/', $line);
225 $glibc_major = trim($line[2]);
226 if (isset($glibc_minor)) {
232 if (strpos($line,
'__GLIBC_MINOR__')) {
235 $line = preg_split(
'/\s+/', $line);
236 $glibc_minor = trim($line[2]);
237 if (isset($glibc_major)) {
243 fclose($features_file);
244 if (!isset($glibc_major) || !isset($glibc_minor)) {
247 return $glibc =
'glibc' . trim($glibc_major) .
"." . trim($glibc_minor) ;
251 $fp = fopen($tmpfile,
"w");
252 fwrite($fp,
"#include <features.h>\n__GLIBC__ __GLIBC_MINOR__\n");
254 $cpp = popen(
"/usr/bin/cpp $tmpfile",
"r");
255 while ($line = fgets($cpp, 1024)) {
256 if ($line[0] ==
'#' || trim($line) ==
'') {
260 if (list($major, $minor) = explode(
' ', trim($line))) {
268 if (!($major && $minor)) {
272 return $glibc =
"glibc{$major}.{$minor}";
277 if (empty($this->extra)) {
278 return "{$this->sysname}-{$this->release}-{$this->cpu}";
280 return "{$this->sysname}-{$this->release}-{$this->cpu}-{$this->extra}";
310 $fragments = is_array($match) ? $match : explode(
'-', $match);
311 $n = count($fragments);
325 return ($matches == $n);
330 if (strcspn($fragment,
'*?') < strlen($fragment)) {
331 $reg =
'/^' . str_replace(array(
'*',
'?',
'/'), array(
'.*',
'.',
'\\/'), $fragment) .
'\\z/';
332 return preg_match($reg, $value);
334 return ($fragment ==
'*' || !strcasecmp($fragment, $value));