Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Feature: add node.cwd() to access the current working directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarter authored and ry committed Sep 1, 2009
1 parent fbf65b5 commit 8ea6adc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/node.cc
Expand Up @@ -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>
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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"),
Expand Down
2 changes: 2 additions & 0 deletions website/api.txt
Expand Up @@ -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
Expand Down

0 comments on commit 8ea6adc

Please sign in to comment.