summaryrefslogtreecommitdiff
path: root/src/node_os.cc
diff options
context:
space:
mode:
authorNathan Rajlich <nathan@tootallnate.net>2012-11-08 12:31:45 -0800
committerNathan Rajlich <nathan@tootallnate.net>2012-11-08 12:31:45 -0800
commit5e4e87ade5ad2dbf525865a3a94694dabb9b1d7f (patch)
treeb990b23dfe175f71374733293b0dbd8f07784e2c /src/node_os.cc
parent3c91a7ae10f0ccabe4550c77189813f8d95785b0 (diff)
downloadnode-new-5e4e87ade5ad2dbf525865a3a94694dabb9b1d7f.tar.gz
os: add os.endianness() function
Diffstat (limited to 'src/node_os.cc')
-rw-r--r--src/node_os.cc9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/node_os.cc b/src/node_os.cc
index c09458e60d..af363d33a5 100644
--- a/src/node_os.cc
+++ b/src/node_os.cc
@@ -41,6 +41,14 @@ namespace node {
using namespace v8;
+static Handle<Value> GetEndianness(const Arguments& args) {
+ HandleScope scope;
+ int i = 1;
+ bool big = (*(char *)&i) == 0;
+ Local<String> endianness = String::New(big ? "BE" : "LE");
+ return scope.Close(endianness);
+}
+
static Handle<Value> GetHostname(const Arguments& args) {
HandleScope scope;
char s[255];
@@ -242,6 +250,7 @@ static Handle<Value> GetInterfaceAddresses(const Arguments& args) {
void OS::Initialize(v8::Handle<v8::Object> target) {
HandleScope scope;
+ NODE_SET_METHOD(target, "getEndianness", GetEndianness);
NODE_SET_METHOD(target, "getHostname", GetHostname);
NODE_SET_METHOD(target, "getLoadAvg", GetLoadAvg);
NODE_SET_METHOD(target, "getUptime", GetUptime);