mirror of https://github.com/lukechilds/node.git
Brian White
14 years ago
committed by
Ryan Dahl
9 changed files with 70 additions and 0 deletions
@ -0,0 +1,7 @@ |
|||
## os Module |
|||
|
|||
Use `require('os')` to access this module. |
|||
|
|||
### tls.getHostname |
|||
|
|||
Returns the hostname of the operating system. |
@ -0,0 +1,3 @@ |
|||
var binding = process.binding('os'); |
|||
|
|||
exports.getHostname = binding.getHostname; |
@ -0,0 +1,34 @@ |
|||
#include <node_os.h> |
|||
|
|||
#include <node.h> |
|||
#include <v8.h> |
|||
|
|||
#include <errno.h> |
|||
#include <unistd.h> // gethostname |
|||
|
|||
namespace node { |
|||
|
|||
using namespace v8; |
|||
|
|||
static Handle<Value> GetHostname(const Arguments& args) { |
|||
HandleScope scope; |
|||
char s[255]; |
|||
int r = gethostname(s, 255); |
|||
|
|||
if (r < 0) { |
|||
return ThrowException(ErrnoException(errno, "gethostname")); |
|||
} |
|||
|
|||
return scope.Close(String::New(s)); |
|||
} |
|||
|
|||
void OS::Initialize(v8::Handle<v8::Object> target) { |
|||
HandleScope scope; |
|||
|
|||
NODE_SET_METHOD(target, "getHostname", GetHostname); |
|||
} |
|||
|
|||
|
|||
} // namespace node
|
|||
|
|||
NODE_MODULE(node_os, node::OS::Initialize); |
@ -0,0 +1,17 @@ |
|||
#ifndef node_os_h |
|||
#define node_os_h |
|||
|
|||
#include <node.h> |
|||
#include <v8.h> |
|||
|
|||
namespace node { |
|||
|
|||
class OS { |
|||
public: |
|||
static void Initialize (v8::Handle<v8::Object> target); |
|||
}; |
|||
|
|||
|
|||
} // namespace node
|
|||
|
|||
#endif // node_os_h
|
@ -0,0 +1,5 @@ |
|||
var common = require('../common'); |
|||
var assert = require('assert'); |
|||
var os = require('os'); |
|||
|
|||
assert.ok(os.getHostname().length > 0); |
Loading…
Reference in new issue