Browse Source

Feature: add node.cwd() to access the current working directory.

v0.7.4-release
Michael Carter 16 years ago
committed by Ryan
parent
commit
8ea6adcae6
  1. 18
      src/node.cc
  2. 2
      website/api.txt

18
src/node.cc

@ -16,6 +16,8 @@
#include <stdlib.h>
#include <strings.h>
#include <assert.h>
#include <unistd.h>
#include <errno.h>
#include <dlfcn.h> /* dlopen(), dlsym() */
#include <string>
@ -102,6 +104,21 @@ ExecuteString(v8::Handle<v8::String> source,
return scope.Close(result);
}
static Handle<Value>
Cwd (const Arguments& args)
{
HandleScope scope;
char output[PATH_MAX];
char *r = getcwd(output, PATH_MAX);
if (r == NULL) {
return ThrowException(Exception::Error(String::New(strerror(errno))));
}
Local<String> cwd = String::New(output);
return scope.Close(cwd);
}
v8::Handle<v8::Value>
node_exit (const v8::Arguments& args)
{
@ -249,6 +266,7 @@ Load (int argc, char *argv[])
NODE_SET_METHOD(node_obj, "compile", compile);
NODE_SET_METHOD(node_obj, "reallyExit", node_exit);
NODE_SET_METHOD(node_obj, "cwd", Cwd);
NODE_SET_METHOD(node_obj, "dlopen", node_dlopen);
node_obj->Set(String::NewSymbol("EventEmitter"),

2
website/api.txt

@ -77,6 +77,8 @@ Like +puts()+ but without the trailing new-line.
+node.exit(code)+::
Immediately ends the process with the specified code.
+node.cwd()+::
Returns the current working directory of the process.
=== Global Variables

Loading…
Cancel
Save