From 0433d828cffaaf1a6a69a8ba175a172ae1af0f11 Mon Sep 17 00:00:00 2001 From: Friedemann Altrock Date: Sun, 22 Nov 2009 19:52:52 +0100 Subject: [PATCH] add process.umask() --- doc/api.txt | 6 +++++- src/node.cc | 14 ++++++++++++++ test/mjsunit/test-umask.js | 6 ++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 test/mjsunit/test-umask.js diff --git a/doc/api.txt b/doc/api.txt index b3a163cf05..8b439cc963 100644 --- a/doc/api.txt +++ b/doc/api.txt @@ -119,6 +119,11 @@ success code 0. +process.cwd()+:: Returns the current working directory of the process. ++process.umask(mask)+ :: +Sets the process's file mode creation mask. Child processes inherit the mask +from the parent process. + - returns the old mask. + +process.kill(pid, signal="SIGTERM")+ :: Send a signal to a process. +pid+ is the process id and +signal+ is the signal to send; for example, "SIGINT" or "SIGUSR1". See kill(2) for more @@ -636,7 +641,6 @@ sys.puts("stats: " + JSON.stringify(stats)); - on success: returns an integer +written+ which specifies how many _bytes_ were written. - on error: no parameters. - +posix.read(fd, length, position, encoding)+:: Read data from the file specified by +fd+. diff --git a/src/node.cc b/src/node.cc index 5185fc50b2..dcb1110035 100644 --- a/src/node.cc +++ b/src/node.cc @@ -275,6 +275,19 @@ static Handle Cwd(const Arguments& args) { return scope.Close(cwd); } +static Handle Umask(const Arguments& args){ + HandleScope scope; + + if(args.Length() < 1 || !args[0]->IsInt32()) { + return ThrowException(Exception::TypeError( + String::New("argument must be an integer."))); + } + unsigned int mask = args[0]->Uint32Value(); + unsigned int old = umask((mode_t)mask); + + return scope.Close(Uint32::New(old)); +} + v8::Handle Exit(const v8::Arguments& args) { int r = 0; if (args.Length() > 0) @@ -683,6 +696,7 @@ static Local Load(int argc, char *argv[]) { NODE_SET_METHOD(process, "reallyExit", Exit); NODE_SET_METHOD(process, "chdir", Chdir); NODE_SET_METHOD(process, "cwd", Cwd); + NODE_SET_METHOD(process, "umask", Umask); NODE_SET_METHOD(process, "dlopen", DLOpen); NODE_SET_METHOD(process, "kill", Kill); NODE_SET_METHOD(process, "memoryUsage", MemoryUsage); diff --git a/test/mjsunit/test-umask.js b/test/mjsunit/test-umask.js new file mode 100644 index 0000000000..1ac9578877 --- /dev/null +++ b/test/mjsunit/test-umask.js @@ -0,0 +1,6 @@ +process.mixin(require("./common")); + +var mask = 0664; +var old = process.umask(mask); + +assertEquals(true, mask === process.umask(old));