3 // +----------------------------------------------------------------------+
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997-2004 The PHP Group |
7 // +----------------------------------------------------------------------+
8 // | This source file is subject to version 3.0 of the PHP license, |
9 // | that is bundled with this package in the file LICENSE, and is |
10 // | available through the world-wide-web at the following url: |
11 // | http://www.php.net/license/3_0.txt. |
12 // | If you did not receive a copy of the PHP license and are unable to |
13 // | obtain it through the world-wide-web, please send a note to |
14 // | license@php.net so we can mail you a copy immediately. |
15 // +----------------------------------------------------------------------+
16 // | Authors: Stig Bakken <ssb@php.net> |
18 // +----------------------------------------------------------------------+
20 // $Id: Guess.php,v 1.13.4.1 2004/10/19 04:15:56 cellog Exp $
24 // php_uname() without args returns the same as 'uname -a', or a PHP-custom
25 // string for Windows.
26 // PHP versions prior to 4.3 return the uname of the host where PHP was built,
27 // as of 4.3 it returns the uname of the host running the PHP code.
29 // PC RedHat Linux 7.1:
30 // Linux host.example.com 2.4.2-2 #1 Sun Apr 8 20:41:30 EDT 2001 i686 unknown
33 // Linux host 2.4.17 #2 SMP Tue Feb 12 15:10:04 CET 2002 i686 unknown
36 // FreeBSD host.example.com 3.3-STABLE FreeBSD 3.3-STABLE #0: Mon Feb 21 00:42:31 CET 2000 root@example.com:/usr/src/sys/compile/CONFIG i386
39 // FreeBSD host.example.com 4.3-RELEASE FreeBSD 4.3-RELEASE #1: Mon Jun 25 11:19:43 EDT 2001 root@example.com:/usr/src/sys/compile/CONFIG i386
42 // FreeBSD host.example.com 4.5-STABLE FreeBSD 4.5-STABLE #0: Wed Feb 6 23:59:23 CET 2002 root@example.com:/usr/src/sys/compile/CONFIG i386
44 // PC FreeBSD 4.5 w/uname from GNU shellutils:
45 // FreeBSD host.example.com 4.5-STABLE FreeBSD 4.5-STABLE #0: Wed Feb i386 unknown
47 // HP 9000/712 HP-UX 10:
48 // HP-UX iq B.10.10 A 9000/712 2008429113 two-user license
50 // HP 9000/712 HP-UX 10 w/uname from GNU shellutils:
51 // HP-UX host B.10.10 A 9000/712 unknown
53 // IBM RS6000/550 AIX 4.3:
54 // AIX host 3 4 000003531C00
56 // AIX 4.3 w/uname from GNU shellutils:
57 // AIX host 3 4 000003531C00 unknown
59 // SGI Onyx IRIX 6.5 w/uname from GNU shellutils:
60 // IRIX64 host 6.5 01091820 IP19 mips
63 // IRIX64 host 6.5 01091820 IP19
65 // SparcStation 20 Solaris 8 w/uname from GNU shellutils:
66 // SunOS host.example.com 5.8 Generic_108528-12 sun4m sparc
68 // SparcStation 20 Solaris 8:
69 // SunOS host.example.com 5.8 Generic_108528-12 sun4m sparc SUNW,SPARCstation-20
72 // Darwin home-eden.local 7.5.0 Darwin Kernel Version 7.5.0: Thu Aug 5 19:26:16 PDT 2004; root:xnu/xnu-517.7.21.obj~3/RELEASE_PPC Power Macintosh
74 // Mac OS X early versions
80 * - define endianness, to allow matchSignature("bigend") etc.
91 function OS_Guess($uname = null)
97 $this->nodename
) = $this->parseSignature($uname);
100 function parseSignature($uname = null)
102 static $sysmap = array(
106 static $cpumap = array(
111 if ($uname === null) {
112 $uname = php_uname();
114 $parts = split('[[:space:]]+', trim($uname));
117 $release = $machine = $cpu = '';
118 $sysname = $parts[0];
119 $nodename = $parts[1];
122 if ($cpu == 'unknown') {
128 $release = "$parts[3].$parts[2]";
136 $release = $parts[1];
142 $extra = $this->_detectGlibcVersion();
143 // use only the first two digits from the kernel version
144 $release = ereg_replace('^([[:digit:]]+\.[[:digit:]]+).*', '\1', $parts[2]);
148 $nodename = $parts[2];
149 $release = $parts[3];
150 if ($cpu == 'Macintosh') {
151 if ($parts[$n - 2] == 'Power') {
157 if ($cpu == 'Macintosh') {
158 if ($parts[$n - 2] == 'Power') {
162 $release = ereg_replace('^([[:digit:]]+\.[[:digit:]]+).*', '\1', $parts[2]);
165 $release = ereg_replace('-.*', '', $parts[2]);
170 if (isset($sysmap[$sysname])) {
171 $sysname = $sysmap[$sysname];
173 $sysname = strtolower($sysname);
175 if (isset($cpumap[$cpu])) {
176 $cpu = $cpumap[$cpu];
178 return array($sysname, $release, $cpu, $extra, $nodename);
181 function _detectGlibcVersion()
183 // Use glibc's <features.h> header file to
184 // get major and minor version number:
185 include_once "System.php";
186 $tmpfile = System
::mktemp("glibctest");
187 $fp = fopen($tmpfile, "w");
188 fwrite($fp, "#include <features.h>\n__GLIBC__ __GLIBC_MINOR__\n");
190 $cpp = popen("/usr/bin/cpp $tmpfile", "r");
192 while ($line = fgets($cpp, 1024)) {
193 if ($line{0} == '#' ||
trim($line) == '') {
196 if (list($major, $minor) = explode(' ', trim($line))) {
202 if (!($major && $minor) && is_link('/lib/libc.so.6')) {
203 // Let's try reading the libc.so.6 symlink
204 if (ereg('^libc-([.*])\.so$', basename(readlink('/lib/libc.so.6')), $matches)) {
205 list($major, $minor) = explode('.', $matches);
208 if (!($major && $minor)) {
211 return "glibc{$major}.{$minor}";
214 function getSignature()
216 if (empty($this->extra
)) {
217 return "{$this->sysname}-{$this->release}-{$this->cpu}";
219 return "{$this->sysname}-{$this->release}-{$this->cpu}-{$this->extra}";
222 function getSysname()
224 return $this->sysname
;
227 function getNodename()
229 return $this->nodename
;
237 function getRelease()
239 return $this->release
;
247 function matchSignature($match)
249 if (is_array($match)) {
252 $fragments = explode('-', $match);
254 $n = count($fragments);
257 $matches +
= $this->_matchFragment($fragments[0], $this->sysname
);
260 $matches +
= $this->_matchFragment($fragments[1], $this->release
);
263 $matches +
= $this->_matchFragment($fragments[2], $this->cpu
);
266 $matches +
= $this->_matchFragment($fragments[3], $this->extra
);
268 return ($matches == $n);
271 function _matchFragment($fragment, $value)
273 if (strcspn($fragment, '*?') < strlen($fragment)) {
274 $reg = '^' . str_replace(array('*', '?', '/'), array('.*', '.', '\\/'), $fragment) . '$';
275 return eregi($reg, $value);
277 return ($fragment == '*' ||
!strcasecmp($fragment, $value));
283 * indent-tabs-mode: nil