Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Add os module and getHostname
Browse files Browse the repository at this point in the history
  • Loading branch information
mscdex authored and ry committed Dec 11, 2010
1 parent dc65cbd commit f1762ff
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmake/node_build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ set(node_sources
src/node_stdio.cc
src/node_timer.cc
src/node_script.cc
src/node_os.cc
src/node_natives.h
${node_extra_src})

Expand Down
1 change: 1 addition & 0 deletions doc/api/_toc.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* [Child Processes](child_processes.html)
* [Assertion Testing](assert.html)
* [TTY](tty.html)
* [OS](os.html)
* Appendixes
* [Appendix 1: Recommended Third-party Modules](appendix_1.html)
* [Appendix 2: Deprecated API's](appendix_2.html)
7 changes: 7 additions & 0 deletions doc/api/os.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## os Module

Use `require('os')` to access this module.

### tls.getHostname

This comment has been minimized.

Copy link
@pquerna

pquerna Dec 11, 2010

shouldn't this be os?


Returns the hostname of the operating system.
3 changes: 3 additions & 0 deletions lib/os.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var binding = process.binding('os');

exports.getHostname = binding.getHostname;
1 change: 1 addition & 0 deletions src/node_extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ NODE_EXT_LIST_ITEM(node_net)
NODE_EXT_LIST_ITEM(node_http_parser)
NODE_EXT_LIST_ITEM(node_signal_watcher)
NODE_EXT_LIST_ITEM(node_stdio)
NODE_EXT_LIST_ITEM(node_os)
NODE_EXT_LIST_END

34 changes: 34 additions & 0 deletions src/node_os.cc
Original file line number Diff line number Diff line change
@@ -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);
17 changes: 17 additions & 0 deletions src/node_os.h
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions test/simple/test-os-hostname.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var common = require('../common');
var assert = require('assert');
var os = require('os');

assert.ok(os.getHostname().length > 0);
1 change: 1 addition & 0 deletions wscript
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ def build(bld):
src/node_stdio.cc
src/node_timer.cc
src/node_script.cc
src/node_os.cc
"""
node.source += bld.env["PLATFORM_FILE"]
if not product_type_is_lib:
Expand Down

0 comments on commit f1762ff

Please sign in to comment.