ProcessUtils.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. //
  2. // Copyright (c) 2008-2017 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "../Precompiled.h"
  23. #include "../Core/ProcessUtils.h"
  24. #include "../IO/FileSystem.h"
  25. #include <cstdio>
  26. #include <fcntl.h>
  27. #ifdef __APPLE__
  28. #include "TargetConditionals.h"
  29. #endif
  30. #if defined(IOS)
  31. #include "../Math/MathDefs.h"
  32. #include <mach/mach_host.h>
  33. #elif !defined(__linux__) && !defined(__EMSCRIPTEN__)
  34. #include <LibCpuId/libcpuid.h>
  35. #endif
  36. #if defined(_WIN32)
  37. #include <windows.h>
  38. #include <io.h>
  39. #if defined(_MSC_VER)
  40. #include <float.h>
  41. #include <Lmcons.h> // For UNLEN.
  42. #elif defined(__MINGW32__)
  43. #include <lmcons.h> // For UNLEN. Apparently MSVC defines "<Lmcons.h>" (with an upperscore 'L' but MinGW uses an underscore 'l').
  44. #include <ntdef.h>
  45. #endif
  46. #elif defined(__linux__) && !defined(__ANDROID__)
  47. #include <pwd.h>
  48. #include <sys/sysinfo.h>
  49. #include <sys/utsname.h>
  50. #elif defined(__APPLE__)
  51. #include <sys/sysctl.h>
  52. #include <SystemConfiguration/SystemConfiguration.h> // For the detection functions inside GetLoginName().
  53. #endif
  54. #ifndef _WIN32
  55. #include <unistd.h>
  56. #endif
  57. #if defined(__EMSCRIPTEN__) && defined(__EMSCRIPTEN_PTHREADS__)
  58. #include <emscripten/threading.h>
  59. #endif
  60. #if defined(__i386__)
  61. // From http://stereopsis.com/FPU.html
  62. #define FPU_CW_PREC_MASK 0x0300
  63. #define FPU_CW_PREC_SINGLE 0x0000
  64. #define FPU_CW_PREC_DOUBLE 0x0200
  65. #define FPU_CW_PREC_EXTENDED 0x0300
  66. #define FPU_CW_ROUND_MASK 0x0c00
  67. #define FPU_CW_ROUND_NEAR 0x0000
  68. #define FPU_CW_ROUND_DOWN 0x0400
  69. #define FPU_CW_ROUND_UP 0x0800
  70. #define FPU_CW_ROUND_CHOP 0x0c00
  71. inline unsigned GetFPUState()
  72. {
  73. unsigned control = 0;
  74. __asm__ __volatile__ ("fnstcw %0" : "=m" (control));
  75. return control;
  76. }
  77. inline void SetFPUState(unsigned control)
  78. {
  79. __asm__ __volatile__ ("fldcw %0" : : "m" (control));
  80. }
  81. #endif
  82. #ifndef MINI_URHO
  83. #include <SDL/SDL.h>
  84. #endif
  85. #include "../DebugNew.h"
  86. namespace Urho3D
  87. {
  88. #ifdef _WIN32
  89. static bool consoleOpened = false;
  90. #endif
  91. static String currentLine;
  92. static Vector<String> arguments;
  93. static String miniDumpDir;
  94. #if defined(IOS)
  95. static void GetCPUData(host_basic_info_data_t* data)
  96. {
  97. mach_msg_type_number_t infoCount;
  98. infoCount = HOST_BASIC_INFO_COUNT;
  99. host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)data, &infoCount);
  100. }
  101. #elif defined(__linux__)
  102. struct CpuCoreCount
  103. {
  104. unsigned numPhysicalCores_;
  105. unsigned numLogicalCores_;
  106. };
  107. // This function is used by all the target triplets with Linux as the OS, such as Android, RPI, desktop Linux, etc
  108. static void GetCPUData(struct CpuCoreCount* data)
  109. {
  110. // Sanity check
  111. assert(data);
  112. // At least return 1 core
  113. data->numPhysicalCores_ = data->numLogicalCores_ = 1;
  114. FILE* fp;
  115. int res;
  116. unsigned i, j;
  117. fp = fopen("/sys/devices/system/cpu/present", "r");
  118. if (fp)
  119. {
  120. res = fscanf(fp, "%d-%d", &i, &j);
  121. fclose(fp);
  122. if (res == 2 && i == 0)
  123. {
  124. data->numPhysicalCores_ = data->numLogicalCores_ = j + 1;
  125. fp = fopen("/sys/devices/system/cpu/cpu0/topology/thread_siblings_list", "r");
  126. if (fp)
  127. {
  128. res = fscanf(fp, "%d,%d,%d,%d", &i, &j, &i, &j);
  129. fclose(fp);
  130. // Having sibling thread(s) indicates the CPU is using HT/SMT technology
  131. if (res > 1)
  132. data->numPhysicalCores_ /= res;
  133. }
  134. }
  135. }
  136. }
  137. #elif !defined(__EMSCRIPTEN__)
  138. static void GetCPUData(struct cpu_id_t* data)
  139. {
  140. if (cpu_identify(0, data) < 0)
  141. {
  142. data->num_logical_cpus = 1;
  143. data->num_cores = 1;
  144. }
  145. }
  146. #endif
  147. void InitFPU()
  148. {
  149. // Make sure FPU is in round-to-nearest, single precision mode
  150. // This ensures Direct3D and OpenGL behave similarly, and all threads behave similarly
  151. #if defined(_MSC_VER) && defined(_M_IX86)
  152. _controlfp(_RC_NEAR | _PC_24, _MCW_RC | _MCW_PC);
  153. #elif defined(__i386__)
  154. unsigned control = GetFPUState();
  155. control &= ~(FPU_CW_PREC_MASK | FPU_CW_ROUND_MASK);
  156. control |= (FPU_CW_PREC_SINGLE | FPU_CW_ROUND_NEAR);
  157. SetFPUState(control);
  158. #endif
  159. }
  160. void ErrorDialog(const String& title, const String& message)
  161. {
  162. #ifndef MINI_URHO
  163. SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title.CString(), message.CString(), 0);
  164. #endif
  165. }
  166. void ErrorExit(const String& message, int exitCode)
  167. {
  168. if (!message.Empty())
  169. PrintLine(message, true);
  170. exit(exitCode);
  171. }
  172. void OpenConsoleWindow()
  173. {
  174. #ifdef _WIN32
  175. if (consoleOpened)
  176. return;
  177. AllocConsole();
  178. freopen("CONIN$", "r", stdin);
  179. freopen("CONOUT$", "w", stdout);
  180. consoleOpened = true;
  181. #endif
  182. }
  183. void PrintUnicode(const String& str, bool error)
  184. {
  185. #if !defined(__ANDROID__) && !defined(IOS)
  186. #ifdef _WIN32
  187. // If the output stream has been redirected, use fprintf instead of WriteConsoleW,
  188. // though it means that proper Unicode output will not work
  189. FILE* out = error ? stderr : stdout;
  190. if (!_isatty(_fileno(out)))
  191. fprintf(out, "%s", str.CString());
  192. else
  193. {
  194. HANDLE stream = GetStdHandle(error ? STD_ERROR_HANDLE : STD_OUTPUT_HANDLE);
  195. if (stream == INVALID_HANDLE_VALUE)
  196. return;
  197. WString strW(str);
  198. DWORD charsWritten;
  199. WriteConsoleW(stream, strW.CString(), strW.Length(), &charsWritten, 0);
  200. }
  201. #else
  202. fprintf(error ? stderr : stdout, "%s", str.CString());
  203. #endif
  204. #endif
  205. }
  206. void PrintUnicodeLine(const String& str, bool error)
  207. {
  208. PrintUnicode(str + "\n", error);
  209. }
  210. void PrintLine(const String& str, bool error)
  211. {
  212. #if !defined(__ANDROID__) && !defined(IOS)
  213. fprintf(error ? stderr : stdout, "%s\n", str.CString());
  214. #endif
  215. }
  216. const Vector<String>& ParseArguments(const String& cmdLine, bool skipFirstArgument)
  217. {
  218. arguments.Clear();
  219. unsigned cmdStart = 0, cmdEnd = 0;
  220. bool inCmd = false;
  221. bool inQuote = false;
  222. for (unsigned i = 0; i < cmdLine.Length(); ++i)
  223. {
  224. if (cmdLine[i] == '\"')
  225. inQuote = !inQuote;
  226. if (cmdLine[i] == ' ' && !inQuote)
  227. {
  228. if (inCmd)
  229. {
  230. inCmd = false;
  231. cmdEnd = i;
  232. // Do not store the first argument (executable name)
  233. if (!skipFirstArgument)
  234. arguments.Push(cmdLine.Substring(cmdStart, cmdEnd - cmdStart));
  235. skipFirstArgument = false;
  236. }
  237. }
  238. else
  239. {
  240. if (!inCmd)
  241. {
  242. inCmd = true;
  243. cmdStart = i;
  244. }
  245. }
  246. }
  247. if (inCmd)
  248. {
  249. cmdEnd = cmdLine.Length();
  250. if (!skipFirstArgument)
  251. arguments.Push(cmdLine.Substring(cmdStart, cmdEnd - cmdStart));
  252. }
  253. // Strip double quotes from the arguments
  254. for (unsigned i = 0; i < arguments.Size(); ++i)
  255. arguments[i].Replace("\"", "");
  256. return arguments;
  257. }
  258. const Vector<String>& ParseArguments(const char* cmdLine)
  259. {
  260. return ParseArguments(String(cmdLine));
  261. }
  262. const Vector<String>& ParseArguments(const WString& cmdLine)
  263. {
  264. return ParseArguments(String(cmdLine));
  265. }
  266. const Vector<String>& ParseArguments(const wchar_t* cmdLine)
  267. {
  268. return ParseArguments(String(cmdLine));
  269. }
  270. const Vector<String>& ParseArguments(int argc, char** argv)
  271. {
  272. String cmdLine;
  273. for (int i = 0; i < argc; ++i)
  274. cmdLine.AppendWithFormat("\"%s\" ", (const char*)argv[i]);
  275. return ParseArguments(cmdLine);
  276. }
  277. const Vector<String>& GetArguments()
  278. {
  279. return arguments;
  280. }
  281. String GetConsoleInput()
  282. {
  283. String ret;
  284. #ifdef URHO3D_TESTING
  285. // When we are running automated tests, reading the console may block. Just return empty in that case
  286. return ret;
  287. #else
  288. #ifdef _WIN32
  289. HANDLE input = GetStdHandle(STD_INPUT_HANDLE);
  290. HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE);
  291. if (input == INVALID_HANDLE_VALUE || output == INVALID_HANDLE_VALUE)
  292. return ret;
  293. // Use char-based input
  294. SetConsoleMode(input, ENABLE_PROCESSED_INPUT);
  295. INPUT_RECORD record;
  296. DWORD events = 0;
  297. DWORD readEvents = 0;
  298. if (!GetNumberOfConsoleInputEvents(input, &events))
  299. return ret;
  300. while (events--)
  301. {
  302. ReadConsoleInputW(input, &record, 1, &readEvents);
  303. if (record.EventType == KEY_EVENT && record.Event.KeyEvent.bKeyDown)
  304. {
  305. unsigned c = record.Event.KeyEvent.uChar.UnicodeChar;
  306. if (c)
  307. {
  308. if (c == '\b')
  309. {
  310. PrintUnicode("\b \b");
  311. int length = currentLine.LengthUTF8();
  312. if (length)
  313. currentLine = currentLine.SubstringUTF8(0, length - 1);
  314. }
  315. else if (c == '\r')
  316. {
  317. PrintUnicode("\n");
  318. ret = currentLine;
  319. currentLine.Clear();
  320. return ret;
  321. }
  322. else
  323. {
  324. // We have disabled echo, so echo manually
  325. wchar_t out = c;
  326. DWORD charsWritten;
  327. WriteConsoleW(output, &out, 1, &charsWritten, 0);
  328. currentLine.AppendUTF8(c);
  329. }
  330. }
  331. }
  332. }
  333. #elif !defined(__ANDROID__) && !defined(IOS)
  334. int flags = fcntl(STDIN_FILENO, F_GETFL);
  335. fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK);
  336. for (;;)
  337. {
  338. int ch = fgetc(stdin);
  339. if (ch >= 0 && ch != '\n')
  340. ret += (char)ch;
  341. else
  342. break;
  343. }
  344. #endif
  345. return ret;
  346. #endif
  347. }
  348. String GetPlatform()
  349. {
  350. #if defined(__ANDROID__)
  351. return "Android";
  352. #elif defined(IOS)
  353. return "iOS";
  354. #elif defined(_WIN32)
  355. return "Windows";
  356. #elif defined(__APPLE__)
  357. return "Mac OS X";
  358. #elif defined(RPI)
  359. return "Raspberry Pi";
  360. #elif defined(__EMSCRIPTEN__)
  361. return "Web";
  362. #elif defined(__linux__)
  363. return "Linux";
  364. #else
  365. return String::EMPTY;
  366. #endif
  367. }
  368. unsigned GetNumPhysicalCPUs()
  369. {
  370. #if defined(IOS)
  371. host_basic_info_data_t data;
  372. GetCPUData(&data);
  373. #if defined(TARGET_IPHONE_SIMULATOR)
  374. // Hardcoded to dual-core on simulator mode even if the host has more
  375. return Min(2, data.physical_cpu);
  376. #else
  377. return data.physical_cpu;
  378. #endif
  379. #elif defined(__linux__)
  380. struct CpuCoreCount data;
  381. GetCPUData(&data);
  382. return data.numPhysicalCores_;
  383. #elif defined(__EMSCRIPTEN__)
  384. #ifdef __EMSCRIPTEN_PTHREADS__
  385. return emscripten_num_logical_cores();
  386. #else
  387. return 1; // Targeting a single-threaded Emscripten build.
  388. #endif
  389. #else
  390. struct cpu_id_t data;
  391. GetCPUData(&data);
  392. return (unsigned)data.num_cores;
  393. #endif
  394. }
  395. unsigned GetNumLogicalCPUs()
  396. {
  397. #if defined(IOS)
  398. host_basic_info_data_t data;
  399. GetCPUData(&data);
  400. #if defined(TARGET_IPHONE_SIMULATOR)
  401. return Min(2, data.logical_cpu);
  402. #else
  403. return data.logical_cpu;
  404. #endif
  405. #elif defined(__linux__)
  406. struct CpuCoreCount data;
  407. GetCPUData(&data);
  408. return data.numLogicalCores_;
  409. #elif defined(__EMSCRIPTEN__)
  410. #ifdef __EMSCRIPTEN_PTHREADS__
  411. return emscripten_num_logical_cores();
  412. #else
  413. return 1; // Targeting a single-threaded Emscripten build.
  414. #endif
  415. #else
  416. struct cpu_id_t data;
  417. GetCPUData(&data);
  418. return (unsigned)data.num_logical_cpus;
  419. #endif
  420. }
  421. void SetMiniDumpDir(const String& pathName)
  422. {
  423. miniDumpDir = AddTrailingSlash(pathName);
  424. }
  425. String GetMiniDumpDir()
  426. {
  427. #ifndef MINI_URHO
  428. if (miniDumpDir.Empty())
  429. {
  430. char* pathName = SDL_GetPrefPath("urho3d", "crashdumps");
  431. if (pathName)
  432. {
  433. String ret(pathName);
  434. SDL_free(pathName);
  435. return ret;
  436. }
  437. }
  438. #endif
  439. return miniDumpDir;
  440. }
  441. unsigned long long GetTotalMemory()
  442. {
  443. #if defined(__linux__) && !defined(__ANDROID__)
  444. struct sysinfo s;
  445. if(sysinfo(&s) != -1)
  446. return s.totalram;
  447. #elif defined(_WIN32)
  448. MEMORYSTATUSEX state;
  449. state.dwLength = sizeof(state);
  450. if(GlobalMemoryStatusEx(&state))
  451. return state.ullTotalPhys;
  452. #elif defined(__APPLE__)
  453. unsigned long long memSize;
  454. size_t len = sizeof(memSize);
  455. int mib[2];
  456. mib[0] = CTL_HW;
  457. mib[1] = HW_MEMSIZE;
  458. sysctl(mib, 2, &memSize, &len, NULL, 0);
  459. return memSize;
  460. #endif
  461. return 0ull;
  462. }
  463. String GetLoginName()
  464. {
  465. #if defined(__linux__) && !defined(__ANDROID__)
  466. struct passwd *p = getpwuid(getuid());
  467. if (p)
  468. return p->pw_name;
  469. #elif defined(_WIN32)
  470. char name[UNLEN + 1];
  471. DWORD len = UNLEN + 1;
  472. if(GetUserName(name, &len))
  473. return name;
  474. #elif defined(__APPLE__)
  475. SCDynamicStoreRef s = SCDynamicStoreCreate(NULL, CFSTR("GetConsoleUser"), NULL, NULL);
  476. if(s != NULL)
  477. {
  478. uid_t u;
  479. CFStringRef n = SCDynamicStoreCopyConsoleUser(s, &u, NULL);
  480. CFRelease(s);
  481. if(n != NULL)
  482. {
  483. char name[256];
  484. Boolean b = CFStringGetCString(n, name, 256, kCFStringEncodingUTF8);
  485. CFRelease(n);
  486. if(b == true)
  487. return name;
  488. }
  489. }
  490. #endif
  491. return "(?)";
  492. }
  493. String GetHostName()
  494. {
  495. #if (defined(__linux__) || defined(__APPLE__)) && !defined(__ANDROID__)
  496. char buffer[256];
  497. if (gethostname(buffer, 256) == 0)
  498. return buffer;
  499. #elif defined(_WIN32)
  500. char buffer[MAX_COMPUTERNAME_LENGTH + 1];
  501. DWORD len = MAX_COMPUTERNAME_LENGTH + 1;
  502. if(GetComputerName(buffer, &len))
  503. return buffer;
  504. #endif
  505. return String::EMPTY;
  506. }
  507. #if defined(_WIN32)
  508. typedef NTSTATUS (WINAPI *RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
  509. static void GetOS(RTL_OSVERSIONINFOW *r)
  510. {
  511. HMODULE m = GetModuleHandle("ntdll.dll");
  512. if (m)
  513. {
  514. RtlGetVersionPtr fPtr = (RtlGetVersionPtr) GetProcAddress(m, "RtlGetVersion");
  515. if (r && fPtr && fPtr(r) == 0)
  516. r->dwOSVersionInfoSize = sizeof *r;
  517. }
  518. }
  519. #endif
  520. String GetOSVersion()
  521. {
  522. #if defined(__linux__) && !defined(__ANDROID__)
  523. struct utsname u;
  524. if(uname(&u) == 0)
  525. return String(u.sysname) + " " + u.release;
  526. #elif defined(_WIN32)
  527. RTL_OSVERSIONINFOW r;
  528. GetOS(&r);
  529. // https://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx
  530. if(r.dwMajorVersion == 5 && r.dwMinorVersion == 0)
  531. return "Windows 2000";
  532. else if(r.dwMajorVersion == 5 && r.dwMinorVersion == 1)
  533. return "Windows XP";
  534. else if(r.dwMajorVersion == 5 && r.dwMinorVersion == 2)
  535. return "Windows XP 64-Bit Edition/Windows Server 2003/Windows Server 2003 R2";
  536. else if(r.dwMajorVersion == 6 && r.dwMinorVersion == 0)
  537. return "Windows Vista/Windows Server 2008";
  538. else if(r.dwMajorVersion == 6 && r.dwMinorVersion == 1)
  539. return "Windows 7/Windows Server 2008 R2";
  540. else if(r.dwMajorVersion == 6 && r.dwMinorVersion == 2)
  541. return "Windows 8/Windows Server 2012";
  542. else if(r.dwMajorVersion == 6 && r.dwMinorVersion == 3)
  543. return "Windows 8.1/Windows Server 2012 R2";
  544. else if(r.dwMajorVersion == 10 && r.dwMinorVersion == 0)
  545. return "Windows 10/Windows Server 2016";
  546. else
  547. return "Windows Unidentified";
  548. #elif defined(__APPLE__)
  549. char kernel_r[256];
  550. size_t size = sizeof(kernel_r);
  551. if(sysctlbyname("kern.osrelease", &kernel_r, &size, NULL, 0) != -1)
  552. {
  553. Vector<String> kernel_version = String(kernel_r).Split('.');
  554. String version = "macOS/Mac OS X ";
  555. int major = atoi(kernel_version[0].CString());
  556. int minor = atoi(kernel_version[1].CString());
  557. int patch = atoi(kernel_version[2].CString());
  558. // https://en.wikipedia.org/wiki/Darwin_(operating_system)
  559. if(major == 16) // macOS Sierra
  560. {
  561. version += "Sierra ";
  562. switch(minor)
  563. {
  564. case 0: version += "10.12.0 "; break;
  565. case 1: version += "10.12.1 "; break;
  566. case 3: version += "10.12.2 "; break;
  567. }
  568. }
  569. else if(major == 15) // OS X El Capitan
  570. {
  571. version += "El Capitan ";
  572. switch(minor)
  573. {
  574. case 0: version += "10.11.0 "; break;
  575. case 6: version += "10.11.6 "; break;
  576. }
  577. }
  578. else if(major == 14) // OS X Yosemite
  579. {
  580. version += "Yosemite ";
  581. switch(minor)
  582. {
  583. case 0: version += "10.10.0 "; break;
  584. case 5: version += "10.10.5 "; break;
  585. }
  586. }
  587. else if(major == 13) // OS X Mavericks
  588. {
  589. version += "Mavericks ";
  590. switch(minor)
  591. {
  592. case 0: version += "10.9.0 "; break;
  593. case 4: version += "10.9.5 "; break;
  594. }
  595. }
  596. else if(major == 12) // OS X Mountain Lion
  597. {
  598. version += "Mountain Lion ";
  599. switch(minor)
  600. {
  601. case 0: version += "10.8.0 "; break;
  602. case 6: version += "10.8.5 "; break;
  603. }
  604. }
  605. else if(major == 11) // Mac OS X Lion
  606. {
  607. version += "Lion ";
  608. switch(minor)
  609. {
  610. case 0: version += "10.7.0 "; break;
  611. case 4: version += "10.7.5 "; break;
  612. }
  613. }
  614. else
  615. {
  616. version += "Unknown ";
  617. }
  618. return version + " (Darwin kernel " + kernel_version[0] + "." + kernel_version[1] + "." + kernel_version[2] + ")";
  619. }
  620. #endif
  621. return String::EMPTY;
  622. }
  623. }