Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

initial commit

  • Loading branch information...
commit ea85f8b3b6da441e38453ac69d8180816c0ae54e 0 parents
David Pacheco authored
19 LICENSE
... ... @@ -0,0 +1,19 @@
  1 +Copyright 2010 David Pacheco. All rights reserved.
  2 +
  3 +Permission is hereby granted, free of charge, to any person obtaining a copy
  4 +of this software and associated documentation files (the "Software"), to
  5 +deal in the Software without restriction, including without limitation the
  6 +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  7 +sell copies of the Software, and to permit persons to whom the Software is
  8 +furnished to do so, subject to the following conditions:
  9 +
  10 +The above copyright notice and this permission notice shall be included in
  11 +all copies or substantial portions of the Software.
  12 +
  13 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  18 +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  19 +IN THE SOFTWARE.
69 README.md
Source Rendered
... ... @@ -0,0 +1,69 @@
  1 +
  2 +node-uname
  3 +==============
  4 +
  5 +Overview
  6 +--------
  7 +
  8 +node-uname is a node.js addon that exposes the standard uname function as
  9 +defined by IEEE Std 1003.1-2001 incorporated into the Single Unix Specification
  10 +v3. The uname function allows software to identify information about the
  11 +currently running system software. This information is useful primarily for
  12 +identification purposes but also as a last resort in determining what
  13 +capabilities are supported by a particular system. Where possible, software
  14 +should test for the presence of specific features rather than hardcode which
  15 +system releases support those features.
  16 +
  17 +
  18 +Status
  19 +------
  20 +
  21 +Complete. No further updates planned.
  22 +
  23 +
  24 +Platforms
  25 +---------
  26 +
  27 +This should work on any platform that implements the "uname" function as
  28 +described by the Single Unix Specification version 3. It is known to work on
  29 +Mac OS X (tested on 10.6.5) and OpenSolaris build 147.
  30 +
  31 +
  32 +Installation
  33 +------------
  34 +
  35 +As an addon, node-uname is installed in the usual way:
  36 +
  37 + # node-waf configure
  38 + # node-waf build
  39 + # node-waf install
  40 +
  41 +
  42 +API
  43 +---
  44 +
  45 +### `uname()`
  46 +
  47 +Returns an object with string members corresponding to the fields of `struct
  48 +utsinfo` as described by the standard. For convenience, these are described
  49 +here:
  50 +
  51 + sysname Name of this implementation of the operating system.
  52 + nodename Name of this node within the communications network to
  53 + which this node is attached, if any.
  54 + release Current release level of this implementation.
  55 + version Current version level of this release.
  56 + machine Name of the hardware type on which the system is running.
  57 +
  58 +This function generally cannot fail except in truly exceptional circumstances
  59 +(like insufficient space to allocate the return value).
  60 +
  61 +
  62 +Example
  63 +--------
  64 +
  65 +### Reimplementing "uname -s" (see uname(1))
  66 +
  67 + var uname = require('uname');
  68 + var utsname = uname.uname();
  69 + console.log(utsname.sysname);
7 examples/uname-a.js
... ... @@ -0,0 +1,7 @@
  1 +var mod_uname = require('uname');
  2 +
  3 +var uts = mod_uname.uname();
  4 +var fields = [ 'sysname', 'nodename', 'release', 'version', 'machine' ];
  5 +var values = fields.map(function (fieldname) { return (uts[fieldname]); });
  6 +
  7 +console.log(values.join(' '));
11 package.json
... ... @@ -0,0 +1,11 @@
  1 +{
  2 + "name": "uname",
  3 + "version": "0.0.1",
  4 + "description": "SUSv3 uname binding",
  5 + "author": "Dave Pacheco (dap@cs.brown.edu)",
  6 + "engines": { "node": "*" },
  7 + "main": "./build/default/uname",
  8 + "scripts": {
  9 + "install": "node-waf configure build"
  10 + }
  11 +}
41 tests/test-uname-a.js
... ... @@ -0,0 +1,41 @@
  1 +var mod_uname = require('uname');
  2 +var mod_cp = require('child_process');
  3 +var ASSERT = require('assert');
  4 +
  5 +var uts = mod_uname.uname();
  6 +var fields = {
  7 + sysname: "-s",
  8 + nodename: "-n",
  9 + release: "-r",
  10 + version: "-v",
  11 + machine: "-m"
  12 +};
  13 +
  14 +var field, nfields;
  15 +
  16 +for (field in uts)
  17 + ASSERT.ok(field in fields);
  18 +
  19 +nfields = 0;
  20 +for (field in fields) {
  21 + nfields++;
  22 + check(field);
  23 +}
  24 +
  25 +function check(field)
  26 +{
  27 + var exec = 'uname ' + fields[field];
  28 +
  29 + mod_cp.exec(exec, function (err, stdout, stderr) {
  30 + var value;
  31 +
  32 + console.log('checking field "%s" with %s', field, exec);
  33 + ASSERT.ok(err === null, 'invocation failed');
  34 +
  35 + /* Chop trailing newline. */
  36 + value = stdout.substring(0, stdout.length - 1);
  37 + console.log('expected output: "%s"', value);
  38 + console.log('actual output: "%s"', uts[field]);
  39 + ASSERT.ok(value === uts[field], 'value mismatch');
  40 + });
  41 +}
40 uname.cc
... ... @@ -0,0 +1,40 @@
  1 +#include <v8.h>
  2 +#include <node.h>
  3 +#include <string.h>
  4 +#include <unistd.h>
  5 +#include <node_object_wrap.h>
  6 +#include <errno.h>
  7 +
  8 +#include <string>
  9 +
  10 +#include <sys/utsname.h>
  11 +
  12 +using namespace v8;
  13 +using std::string;
  14 +
  15 +Handle<Value> call_uname(const Arguments& args)
  16 +{
  17 + HandleScope scope;
  18 + struct utsname uts;
  19 +
  20 + (void) uname(&uts);
  21 +
  22 + Local<Object> rv = Object::New();
  23 +
  24 + rv->Set(String::New("sysname"), String::New(uts.sysname));
  25 + rv->Set(String::New("nodename"), String::New(uts.nodename));
  26 + rv->Set(String::New("release"), String::New(uts.release));
  27 + rv->Set(String::New("version"), String::New(uts.version));
  28 + rv->Set(String::New("machine"), String::New(uts.machine));
  29 +
  30 + return (rv);
  31 +}
  32 +
  33 +extern "C" void
  34 +init (Handle<Object> target)
  35 +{
  36 + HandleScope scope;
  37 + Local<FunctionTemplate> templ = FunctionTemplate::New(call_uname);
  38 +
  39 + target->Set(String::NewSymbol("uname"), templ->GetFunction());
  40 +}
15 wscript
... ... @@ -0,0 +1,15 @@
  1 +srcdir = '.'
  2 +blddir = 'build'
  3 +VERSION = '0.0.1'
  4 +
  5 +def set_options(opt):
  6 + opt.tool_options('compiler_cxx')
  7 +
  8 +def configure(conf):
  9 + conf.check_tool('compiler_cxx')
  10 + conf.check_tool('node_addon')
  11 +
  12 +def build(bld):
  13 + obj = bld.new_task_gen('cxx', 'shlib', 'node_addon')
  14 + obj.target = 'uname'
  15 + obj.source = 'uname.cc'

0 comments on commit ea85f8b

Please sign in to comment.
Something went wrong with that request. Please try again.