Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dave Pacheco
committed
Jan 6, 2011
0 parents
commit ea85f8b
Showing
7 changed files
with
202 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright 2010 David Pacheco. All rights reserved. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to | ||
deal in the Software without restriction, including without limitation the | ||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
sell copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
|
||
node-uname | ||
============== | ||
|
||
Overview | ||
-------- | ||
|
||
node-uname is a node.js addon that exposes the standard uname function as | ||
defined by IEEE Std 1003.1-2001 incorporated into the Single Unix Specification | ||
v3. The uname function allows software to identify information about the | ||
currently running system software. This information is useful primarily for | ||
identification purposes but also as a last resort in determining what | ||
capabilities are supported by a particular system. Where possible, software | ||
should test for the presence of specific features rather than hardcode which | ||
system releases support those features. | ||
|
||
|
||
Status | ||
------ | ||
|
||
Complete. No further updates planned. | ||
|
||
|
||
Platforms | ||
--------- | ||
|
||
This should work on any platform that implements the "uname" function as | ||
described by the Single Unix Specification version 3. It is known to work on | ||
Mac OS X (tested on 10.6.5) and OpenSolaris build 147. | ||
|
||
|
||
Installation | ||
------------ | ||
|
||
As an addon, node-uname is installed in the usual way: | ||
|
||
# node-waf configure | ||
# node-waf build | ||
# node-waf install | ||
|
||
|
||
API | ||
--- | ||
|
||
### `uname()` | ||
|
||
Returns an object with string members corresponding to the fields of `struct | ||
utsinfo` as described by the standard. For convenience, these are described | ||
here: | ||
|
||
sysname Name of this implementation of the operating system. | ||
nodename Name of this node within the communications network to | ||
which this node is attached, if any. | ||
release Current release level of this implementation. | ||
version Current version level of this release. | ||
machine Name of the hardware type on which the system is running. | ||
|
||
This function generally cannot fail except in truly exceptional circumstances | ||
(like insufficient space to allocate the return value). | ||
|
||
|
||
Example | ||
-------- | ||
|
||
### Reimplementing "uname -s" (see uname(1)) | ||
|
||
var uname = require('uname'); | ||
var utsname = uname.uname(); | ||
console.log(utsname.sysname); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var mod_uname = require('uname'); | ||
|
||
var uts = mod_uname.uname(); | ||
var fields = [ 'sysname', 'nodename', 'release', 'version', 'machine' ]; | ||
var values = fields.map(function (fieldname) { return (uts[fieldname]); }); | ||
|
||
console.log(values.join(' ')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "uname", | ||
"version": "0.0.1", | ||
"description": "SUSv3 uname binding", | ||
"author": "Dave Pacheco (dap@cs.brown.edu)", | ||
"engines": { "node": "*" }, | ||
"main": "./build/default/uname", | ||
"scripts": { | ||
"install": "node-waf configure build" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
var mod_uname = require('uname'); | ||
var mod_cp = require('child_process'); | ||
var ASSERT = require('assert'); | ||
|
||
var uts = mod_uname.uname(); | ||
var fields = { | ||
sysname: "-s", | ||
nodename: "-n", | ||
release: "-r", | ||
version: "-v", | ||
machine: "-m" | ||
}; | ||
|
||
var field, nfields; | ||
|
||
for (field in uts) | ||
ASSERT.ok(field in fields); | ||
|
||
nfields = 0; | ||
for (field in fields) { | ||
nfields++; | ||
check(field); | ||
} | ||
|
||
function check(field) | ||
{ | ||
var exec = 'uname ' + fields[field]; | ||
|
||
mod_cp.exec(exec, function (err, stdout, stderr) { | ||
var value; | ||
|
||
console.log('checking field "%s" with %s', field, exec); | ||
ASSERT.ok(err === null, 'invocation failed'); | ||
|
||
/* Chop trailing newline. */ | ||
value = stdout.substring(0, stdout.length - 1); | ||
console.log('expected output: "%s"', value); | ||
console.log('actual output: "%s"', uts[field]); | ||
ASSERT.ok(value === uts[field], 'value mismatch'); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <v8.h> | ||
#include <node.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
#include <node_object_wrap.h> | ||
#include <errno.h> | ||
|
||
#include <string> | ||
|
||
#include <sys/utsname.h> | ||
|
||
using namespace v8; | ||
using std::string; | ||
|
||
Handle<Value> call_uname(const Arguments& args) | ||
{ | ||
HandleScope scope; | ||
struct utsname uts; | ||
|
||
(void) uname(&uts); | ||
|
||
Local<Object> rv = Object::New(); | ||
|
||
rv->Set(String::New("sysname"), String::New(uts.sysname)); | ||
rv->Set(String::New("nodename"), String::New(uts.nodename)); | ||
rv->Set(String::New("release"), String::New(uts.release)); | ||
rv->Set(String::New("version"), String::New(uts.version)); | ||
rv->Set(String::New("machine"), String::New(uts.machine)); | ||
|
||
return (rv); | ||
} | ||
|
||
extern "C" void | ||
init (Handle<Object> target) | ||
{ | ||
HandleScope scope; | ||
Local<FunctionTemplate> templ = FunctionTemplate::New(call_uname); | ||
|
||
target->Set(String::NewSymbol("uname"), templ->GetFunction()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
srcdir = '.' | ||
blddir = 'build' | ||
VERSION = '0.0.1' | ||
|
||
def set_options(opt): | ||
opt.tool_options('compiler_cxx') | ||
|
||
def configure(conf): | ||
conf.check_tool('compiler_cxx') | ||
conf.check_tool('node_addon') | ||
|
||
def build(bld): | ||
obj = bld.new_task_gen('cxx', 'shlib', 'node_addon') | ||
obj.target = 'uname' | ||
obj.source = 'uname.cc' |