Skip to content

Instantly share code, notes, and snippets.

@piscisaureus
Created January 5, 2011 02:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piscisaureus/765839 to your computer and use it in GitHub Desktop.
Save piscisaureus/765839 to your computer and use it in GitHub Desktop.
0001-Implement-os.isWindows
From 7f1bc3cff28d08ce4cae609bddec795b67ff6e0e Mon Sep 17 00:00:00 2001
From: Bert Belder <bertbelder@gmail.com>
Date: Wed, 5 Jan 2011 03:30:27 +0100
Subject: [PATCH] Implement os.isWindows
---
doc/api/os.markdown | 4 ++++
lib/os.js | 3 ++-
src/node_os.cc | 6 ++++++
3 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/doc/api/os.markdown b/doc/api/os.markdown
index 3c4e1b4..477fcba 100644
--- a/doc/api/os.markdown
+++ b/doc/api/os.markdown
@@ -14,6 +14,10 @@ Returns the operating system name.
Returns the operating system release.
+### os.isWindows
+
+True on windows, false otherwise.
+
### os.uptime()
Returns the system uptime in seconds.
diff --git a/lib/os.js b/lib/os.js
index 5b1bb22..007070d 100644
--- a/lib/os.js
+++ b/lib/os.js
@@ -7,4 +7,5 @@ exports.freemem = binding.getFreeMem;
exports.totalmem = binding.getTotalMem;
exports.cpus = binding.getCPUs;
exports.type = binding.getOSType;
-exports.release = binding.getOSRelease;
\ No newline at end of file
+exports.release = binding.getOSRelease;
+exports.isWindows = binding.isWindows;
\ No newline at end of file
diff --git a/src/node_os.cc b/src/node_os.cc
index 7586488..fd6395e 100644
--- a/src/node_os.cc
+++ b/src/node_os.cc
@@ -145,6 +145,12 @@ void OS::Initialize(v8::Handle<v8::Object> target) {
NODE_SET_METHOD(target, "getCPUs", GetCPUInfo);
NODE_SET_METHOD(target, "getOSType", GetOSType);
NODE_SET_METHOD(target, "getOSRelease", GetOSRelease);
+
+#ifdef __POSIX__
+ target->Set(String::New("isWindows"), False());
+#else // __MINGW32__
+ target->Set(String::New("isWindows"), True());
+#endif
}
--
1.7.3.1.msysgit.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment