Skip to content

Commit

Permalink
Added utils
Browse files Browse the repository at this point in the history
  • Loading branch information
samkrew committed Feb 16, 2015
1 parent 97813da commit 1510033
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ libmbus
build
src/old.cc
node_modules
*.build
*.build
npm-debug.log
15 changes: 15 additions & 0 deletions src/util.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "util.h"
#include <cstdlib>
#include <cstring>

char *get(v8::Handle<v8::Value> value, const char *fallback) {
if (value->IsString()) {
v8::String::AsciiValue string(value);
char *str = (char *) malloc(string.length() + 1);
strcpy(str, *string);
return str;
}
char *str = (char *) malloc(strlen(fallback) + 1);
strcpy(str, fallback);
return str;
}
9 changes: 9 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef UTIL_H
#define UTIL_H

#include <node.h>
#include <v8.h>

char *get(v8::Handle<v8::Value> value, const char *fallback = "");

#endif

0 comments on commit 1510033

Please sign in to comment.