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

Commit

Permalink
add process.umask()
Browse files Browse the repository at this point in the history
  • Loading branch information
fwg authored and ry committed Nov 22, 2009
1 parent 2d54d66 commit 0433d82
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion doc/api.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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+.
Expand Down
14 changes: 14 additions & 0 deletions src/node.cc
Expand Up @@ -275,6 +275,19 @@ static Handle<Value> Cwd(const Arguments& args) {
return scope.Close(cwd);
}

static Handle<Value> 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<v8::Value> Exit(const v8::Arguments& args) {
int r = 0;
if (args.Length() > 0)
Expand Down Expand Up @@ -683,6 +696,7 @@ static Local<Object> 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);
Expand Down
6 changes: 6 additions & 0 deletions 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));

0 comments on commit 0433d82

Please sign in to comment.