1
0
mirror of https://github.com/termux/termux-packages synced 2024-06-26 20:17:09 +00:00
termux-packages/packages/nodejs/src-node_os.cc.patch
2022-10-06 10:34:28 +05:30

45 lines
1.5 KiB
Diff

--- ./src/node_os.cc.orig 2022-10-05 20:33:26.560099607 +0530
+++ ./src/node_os.cc 2022-10-05 20:41:12.950099429 +0530
@@ -31,6 +31,8 @@
# include <climits> // PATH_MAX on Solaris.
#endif // __POSIX__
+#include <sys/sysinfo.h>
+
#include <array>
#include <cerrno>
#include <cstring>
@@ -97,6 +99,16 @@
arraysize(osInformation)));
}
+static void GetNumCPUs(const FunctionCallbackInfo<Value>& args) {
+ Environment* env = Environment::GetCurrent(args);
+ Isolate* isolate = env->isolate();
+ int n = get_nprocs();
+ if (n < 1) {
+ n = 1;
+ }
+ args.GetReturnValue().Set(Number::New(isolate, n));
+}
+
static void GetCPUInfo(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
Isolate* isolate = env->isolate();
@@ -391,6 +403,7 @@
SetMethod(context, target, "getUptime", GetUptime);
SetMethod(context, target, "getTotalMem", GetTotalMemory);
SetMethod(context, target, "getFreeMem", GetFreeMemory);
+ SetMethod(context, target, "getNumCPUs", GetNumCPUs);
SetMethod(context, target, "getCPUs", GetCPUInfo);
SetMethod(context, target, "getInterfaceAddresses", GetInterfaceAddresses);
SetMethod(context, target, "getHomeDirectory", GetHomeDirectory);
@@ -411,6 +424,7 @@
registry->Register(GetUptime);
registry->Register(GetTotalMemory);
registry->Register(GetFreeMemory);
+ registry->Register(GetNumCPUs);
registry->Register(GetCPUInfo);
registry->Register(GetInterfaceAddresses);
registry->Register(GetHomeDirectory);