2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
16 #include "hphp/util/kernel-version.h"
17 #include "hphp/util/assertions.h"
18 #include "hphp/util/portability.h"
27 #include <sys/utsname.h>
32 void KernelVersion::parse(const char* s
) {
34 // Assume no part of the uname string will be more than 128 chars
40 "%d.%d%1[.-]%127[A-Za-z0-9]-%127[A-Za-z0-9]_fbk%d_",
41 &m_major
, &m_minor
, dashdot
, release
, build
, &m_fbk
);
42 m_release_str
= release
[0] == 0 ? "" : (const char*) release
;
43 m_build_str
= build
[0] == 0 ? "" : (const char*) build
;
44 // Populate the int-based release and build, if we have all digits in them
45 if (isNumber(m_release_str
)) {
46 m_release
= atoi(m_release_str
.c_str());
48 if (isNumber(m_build_str
)) {
49 m_build
= atoi(m_build_str
.c_str());
53 KernelVersion::KernelVersion() {
56 verInf
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
57 GetVersionEx(&verInf
);
58 m_major
= verInf
.dwMajorVersion
;
59 m_minor
= verInf
.dwMinorVersion
;
60 m_build
= verInf
.dwBuildNumber
;
61 m_release
= verInf
.dwPlatformId
;
64 DEBUG_ONLY
int err
= uname(&uts
);
70 KernelVersion::KernelVersion(const char* s
) {
71 m_major
= m_minor
= m_fbk
= m_release
= m_build
= -1;
72 m_release_str
= m_build_str
= "";
76 bool KernelVersion::isNumber(const std::string s
) {
77 return !s
.empty() && s
.find_first_not_of("0123456789") == std::string::npos
;