/
EvilBeaver
/
OneScript
Обзор
Документация
Войти
/
EvilBeaver
/
OneScript
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
v2.0.2
src/OneScript.StandardLibrary/SystemHelper.cs
48 строк
1 KB
EvilBeaver
Merge remote-tracking branch 'remotes/origin/release/v1.8.1' into feature/compiler-v2
24 сен 2022, 19:04
24 сен 2022, 19:04
ec40cab
Код
Авторство
О чём код?
/*---------------------------------------------------------- This Source Code Form is subject to the terms of the Mozilla Public License, v.2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. ----------------------------------------------------------*/ using System; using System.Runtime.InteropServices; namespace ScriptEngine.HostedScript.Library { internal static class SystemHelper { public static string UnixKernelName() { return KernelNameInternal(); } [DllImport("libc")] private static extern int uname(IntPtr buf); private static string KernelNameInternal() { IntPtr buf = IntPtr.Zero; try { // https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_utsname.h.html // стандартом размер структуры не определён, поэтому считаем, что 8K хватит всем buf = Marshal.AllocHGlobal(8192); if (uname(buf) == 0) { var osKernelName = Marshal.PtrToStringAnsi(buf); return osKernelName; } } finally { if (buf != IntPtr.Zero) { Marshal.FreeHGlobal(buf); } } return null; } } }