Skip to content

Instantly share code, notes, and snippets.

@jclulow
Created May 16, 2016 23:53
Show Gist options
  • Select an option

  • Save jclulow/cf3f7564447ae68eb5de7e08b76c42b2 to your computer and use it in GitHub Desktop.

Select an option

Save jclulow/cf3f7564447ae68eb5de7e08b76c42b2 to your computer and use it in GitHub Desktop.
/*
* Copyright 2016 Joyent, Inc.
*/
#include <stdlib.h>
#include <node_version.h>
#include <errno.h>
#include <sys/utsname.h>
#include "v8plus_glue.h"
static nvlist_t *
newapi_uname(const nvlist_t *arg __UNUSED)
{
struct utsname uts;
if (uname(&uts) < 0) {
return (v8plus_syserr(errno, "uname"));
}
return (v8plus_obj(
V8PLUS_TYPE_INL_OBJECT, "res",
V8PLUS_TYPE_STRING, "sysname", uts.sysname,
V8PLUS_TYPE_STRING, "nodename", uts.nodename,
V8PLUS_TYPE_STRING, "release", uts.release,
V8PLUS_TYPE_STRING, "version", uts.version,
V8PLUS_TYPE_STRING, "machine", uts.machine,
V8PLUS_TYPE_NONE,
V8PLUS_TYPE_NONE));
}
static nvlist_t *
newapi_void(const nvlist_t *arg __UNUSED)
{
return (v8plus_void());
}
static v8plus_module_defn_t vmd = {
.vmd_version = V8PLUS_MODULE_VERSION,
.vmd_static_methods = (v8plus_static_descr_t[]) {
{
.sd_name = "newapi_uname",
.sd_c_func = newapi_uname
},
{
.sd_name = "newapi_void",
.sd_c_func = newapi_void
}
},
.vmd_static_method_count = 2
};
__attribute__((constructor))
static void
_init(void)
{
v8plus_module_register(&vmd);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment