Bearsampp 2026.9.23
Loading...
Searching...
No Matches
OS_Guess Class Reference

Public Member Functions

 __construct ($uname=null)
 _detectGlibcVersion ()
 _determineIfPowerpc ($cpu, $parts)
 _fromGlibCTest ()
 _IsADefinition ($line)
 _matchFragment ($fragment, $value)
 _parseFeaturesHeaderFile ($features_header_file)
 _readGlibCVersionFromFeaturesHeaderFile ()
 _readGlibCVersionFromSymlink ($file)
 getCpu ()
 getExtra ()
 getNodename ()
 getRelease ()
 getSignature ()
 getSysname ()
 matchSignature ($match)
 parseSignature ($uname=null)

Data Fields

 $cpu
 $extra
 $nodename
 $release
 $sysname

Detailed Description

Definition at line 93 of file Guess.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( $uname = null)

Definition at line 101 of file Guess.php.

102 {
103 list($this->sysname,
104 $this->release,
105 $this->cpu,
106 $this->extra,
107 $this->nodename) = $this->parseSignature($uname);
108 }
parseSignature($uname=null)
Definition Guess.php:110

References parseSignature().

Here is the call graph for this function:

Member Function Documentation

◆ _detectGlibcVersion()

_detectGlibcVersion ( )

Definition at line 187 of file Guess.php.

188 {
189 static $glibc = false;
190 if ($glibc !== false) {
191 return $glibc; // no need to run this multiple times
192 }
193 $major = $minor = 0;
194 include_once "System.php";
195
196 // Let's try reading possible libc.so.6 symlinks
197 $libcs = array(
198 '/lib64/libc.so.6',
199 '/lib/libc.so.6',
200 '/lib/i386-linux-gnu/libc.so.6'
201 );
202 $versions = array();
203 foreach ($libcs as $file) {
204 $versions = $this->_readGlibCVersionFromSymlink($file);
205 if ($versions != []) {
206 list($major, $minor) = $versions;
207 break;
208 }
209 }
210
211 // Use glibc's <features.h> header file to
212 // get major and minor version number:
213 if (!($major && $minor)) {
214 $versions = $this->_readGlibCVersionFromFeaturesHeaderFile();
215 }
216 if (is_array($versions) && $versions != []) {
217 list($major, $minor) = $versions;
218 }
219
220 if (!($major && $minor)) {
221 return $glibc = '';
222 }
223
224 return $glibc = "glibc{$major}.{$minor}";
225 }
_readGlibCVersionFromFeaturesHeaderFile()
Definition Guess.php:239
_readGlibCVersionFromSymlink($file)
Definition Guess.php:227

References _readGlibCVersionFromFeaturesHeaderFile(), and _readGlibCVersionFromSymlink().

Referenced by parseSignature().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _determineIfPowerpc()

_determineIfPowerpc ( $cpu,
$parts )

Definition at line 178 of file Guess.php.

179 {
180 $n = count($parts);
181 if ($cpu == 'Macintosh' && $parts[$n - 2] == 'Power') {
182 $cpu = 'powerpc';
183 }
184 return $cpu;
185 }

References $cpu.

Referenced by parseSignature().

Here is the caller graph for this function:

◆ _fromGlibCTest()

_fromGlibCTest ( )

Definition at line 297 of file Guess.php.

298 {
299 $major = null;
300 $minor = null;
301
302 $tmpfile = System::mktemp("glibctest");
303 $fp = fopen($tmpfile, "w");
304 fwrite($fp, "#include <features.h>\n__GLIBC__ __GLIBC_MINOR__\n");
305 fclose($fp);
306 $cpp = popen("/usr/bin/cpp $tmpfile", "r");
307 while ($line = fgets($cpp, 1024)) {
308 if ($line[0] == '#' || trim($line) == '') {
309 continue;
310 }
311
312 if (list($major, $minor) = explode(' ', trim($line))) {
313 break;
314 }
315 }
316 pclose($cpp);
317 unlink($tmpfile);
318 if ($major !== null && $minor !== null) {
319 return [$major, $minor];
320 }
321 }
static mktemp($args=null)
Definition System.php:395

Referenced by _readGlibCVersionFromFeaturesHeaderFile().

Here is the caller graph for this function:

◆ _IsADefinition()

_IsADefinition ( $line)

Definition at line 289 of file Guess.php.

290 {
291 if ($line === false) {
292 return false;
293 }
294 return strpos(trim($line), '#define') !== false;
295 }

Referenced by _parseFeaturesHeaderFile().

Here is the caller graph for this function:

◆ _matchFragment()

_matchFragment ( $fragment,
$value )

Definition at line 376 of file Guess.php.

377 {
378 if (strcspn($fragment, '*?') < strlen($fragment)) {
379 $expression = str_replace(
380 array('*', '?', '/'),
381 array('.*', '.', '\\/'),
382 $fragment
383 );
384 $reg = '/^' . $expression . '\\z/';
385 return preg_match($reg, $value);
386 }
387 return ($fragment == '*' || !strcasecmp($fragment, $value));
388 }

Referenced by matchSignature().

Here is the caller graph for this function:

◆ _parseFeaturesHeaderFile()

_parseFeaturesHeaderFile ( $features_header_file)

Definition at line 254 of file Guess.php.

255 {
256 $features_file = fopen($features_header_file, 'rb');
257 while (!feof($features_file)) {
258 $line = fgets($features_file, 8192);
259 if (!$this->_IsADefinition($line)) {
260 continue;
261 }
262 if (strpos($line, '__GLIBC__')) {
263 // major version number #define __GLIBC__ version
264 $line = preg_split('/\s+/', $line);
265 $glibc_major = trim($line[2]);
266 if (isset($glibc_minor)) {
267 break;
268 }
269 continue;
270 }
271
272 if (strpos($line, '__GLIBC_MINOR__')) {
273 // got the minor version number
274 // #define __GLIBC_MINOR__ version
275 $line = preg_split('/\s+/', $line);
276 $glibc_minor = trim($line[2]);
277 if (isset($glibc_major)) {
278 break;
279 }
280 }
281 }
282 fclose($features_file);
283 if (!isset($glibc_major) || !isset($glibc_minor)) {
284 return array();
285 }
286 return array(trim($glibc_major), trim($glibc_minor));
287 }
_IsADefinition($line)
Definition Guess.php:289

References _IsADefinition().

Referenced by _readGlibCVersionFromFeaturesHeaderFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _readGlibCVersionFromFeaturesHeaderFile()

_readGlibCVersionFromFeaturesHeaderFile ( )

Definition at line 239 of file Guess.php.

240 {
241 $features_header_file = '/usr/include/features.h';
242 if (!(@file_exists($features_header_file)
243 && @is_readable($features_header_file))
244 ) {
245 return array();
246 }
247 if (!@file_exists('/usr/bin/cpp') || !@is_executable('/usr/bin/cpp')) {
248 return $this->_parseFeaturesHeaderFile($features_header_file);
249 } // no cpp
250
251 return $this->_fromGlibCTest();
252 }
_parseFeaturesHeaderFile($features_header_file)
Definition Guess.php:254
_fromGlibCTest()
Definition Guess.php:297

References _fromGlibCTest(), and _parseFeaturesHeaderFile().

Referenced by _detectGlibcVersion().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _readGlibCVersionFromSymlink()

_readGlibCVersionFromSymlink ( $file)

Definition at line 227 of file Guess.php.

228 {
229 $versions = array();
230 if (@is_link($file)
231 && (preg_match('/^libc-(.*)\.so$/', basename(readlink($file)), $matches))
232 ) {
233 $versions = explode('.', $matches[1]);
234 }
235 return $versions;
236 }

Referenced by _detectGlibcVersion().

Here is the caller graph for this function:

◆ getCpu()

getCpu ( )

Definition at line 341 of file Guess.php.

342 {
343 return $this->cpu;
344 }

References $cpu.

◆ getExtra()

getExtra ( )

Definition at line 351 of file Guess.php.

352 {
353 return $this->extra;
354 }

References $extra.

◆ getNodename()

getNodename ( )

Definition at line 336 of file Guess.php.

337 {
338 return $this->nodename;
339 }
$nodename
Definition Guess.php:96

References $nodename.

◆ getRelease()

getRelease ( )

Definition at line 346 of file Guess.php.

347 {
348 return $this->release;
349 }

References $release.

◆ getSignature()

getSignature ( )

Definition at line 323 of file Guess.php.

324 {
325 if (empty($this->extra)) {
326 return "{$this->sysname}-{$this->release}-{$this->cpu}";
327 }
328 return "{$this->sysname}-{$this->release}-{$this->cpu}-{$this->extra}";
329 }

◆ getSysname()

getSysname ( )

Definition at line 331 of file Guess.php.

332 {
333 return $this->sysname;
334 }

References $sysname.

◆ matchSignature()

matchSignature ( $match)

Definition at line 356 of file Guess.php.

357 {
358 $fragments = is_array($match) ? $match : explode('-', $match);
359 $n = count($fragments);
360 $matches = 0;
361 if ($n > 0) {
362 $matches += $this->_matchFragment($fragments[0], $this->sysname);
363 }
364 if ($n > 1) {
365 $matches += $this->_matchFragment($fragments[1], $this->release);
366 }
367 if ($n > 2) {
368 $matches += $this->_matchFragment($fragments[2], $this->cpu);
369 }
370 if ($n > 3) {
371 $matches += $this->_matchFragment($fragments[3], $this->extra);
372 }
373 return ($matches == $n);
374 }
_matchFragment($fragment, $value)
Definition Guess.php:376

References _matchFragment().

Here is the call graph for this function:

◆ parseSignature()

parseSignature ( $uname = null)

Definition at line 110 of file Guess.php.

111 {
112 static $sysmap = array(
113 'HP-UX' => 'hpux',
114 'IRIX64' => 'irix',
115 );
116 static $cpumap = array(
117 'i586' => 'i386',
118 'i686' => 'i386',
119 'ppc' => 'powerpc',
120 );
121 if ($uname === null) {
122 $uname = php_uname();
123 }
124 $parts = preg_split('/\s+/', trim($uname));
125 $n = count($parts);
126
127 $release = $machine = $cpu = '';
128 $sysname = $parts[0];
129 $nodename = $parts[1];
130 $cpu = $parts[$n-1];
131 $extra = '';
132 if ($cpu == 'unknown') {
133 $cpu = $parts[$n - 2];
134 }
135
136 switch ($sysname) {
137 case 'AIX' :
138 $release = "$parts[3].$parts[2]";
139 break;
140 case 'Windows' :
141 $release = $parts[1];
142 if ($release == '95/98') {
143 $release = '9x';
144 }
145 $cpu = 'i386';
146 break;
147 case 'Linux' :
148 $extra = $this->_detectGlibcVersion();
149 // use only the first two digits from the kernel version
150 $release = preg_replace('/^([0-9]+\.[0-9]+).*/', '\1', $parts[2]);
151 break;
152 case 'Mac' :
153 $sysname = 'darwin';
154 $nodename = $parts[2];
155 $release = $parts[3];
156 $cpu = $this->_determineIfPowerpc($cpu, $parts);
157 break;
158 case 'Darwin' :
159 $cpu = $this->_determineIfPowerpc($cpu, $parts);
160 $release = preg_replace('/^([0-9]+\.[0-9]+).*/', '\1', $parts[2]);
161 break;
162 default:
163 $release = preg_replace('/-.*/', '', $parts[2]);
164 break;
165 }
166
167 if (isset($sysmap[$sysname])) {
168 $sysname = $sysmap[$sysname];
169 } else {
170 $sysname = strtolower($sysname);
171 }
172 if (isset($cpumap[$cpu])) {
173 $cpu = $cpumap[$cpu];
174 }
175 return array($sysname, $release, $cpu, $extra, $nodename);
176 }
_determineIfPowerpc($cpu, $parts)
Definition Guess.php:178
_detectGlibcVersion()
Definition Guess.php:187

References $cpu, $extra, $nodename, $release, $sysname, _detectGlibcVersion(), and _determineIfPowerpc().

Referenced by __construct().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ $cpu

$cpu

Definition at line 97 of file Guess.php.

Referenced by _determineIfPowerpc(), getCpu(), and parseSignature().

◆ $extra

$extra

Definition at line 99 of file Guess.php.

Referenced by getExtra(), and parseSignature().

◆ $nodename

$nodename

Definition at line 96 of file Guess.php.

Referenced by getNodename(), and parseSignature().

◆ $release

$release

Definition at line 98 of file Guess.php.

Referenced by getRelease(), and parseSignature().

◆ $sysname

$sysname

Definition at line 95 of file Guess.php.

Referenced by getSysname(), and parseSignature().


The documentation for this class was generated from the following file:
  • E:/Bearsampp-development/sandbox/core/libs/php/pear/pear/OS/Guess.php