Updated patch of node.cc for supporting reading of umask

This commit is contained in:
Rasmus Andersson 2010-02-27 18:18:41 +01:00 committed by Ryan Dahl
parent a258992855
commit 374300ca8d
3 changed files with 21 additions and 10 deletions

View File

@ -143,10 +143,11 @@ Gets/sets the group identity of the process. (See setgid(2).)
+process.chdir(directory)+::
Changes 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.umask([mask])+ ::
Sets or read the process's file mode creation mask. Child processes inherit
the mask from the parent process.
- returns the old mask if +mask+ argument is given, otherwise returns
the current mask.
+process.kill(pid, signal="SIGTERM")+ ::
Send a signal to a process. +pid+ is the process id and +signal+ is the

View File

@ -471,14 +471,18 @@ static Handle<Value> Cwd(const Arguments& args) {
static Handle<Value> Umask(const Arguments& args){
HandleScope scope;
if(args.Length() < 1 || !args[0]->IsInt32()) {
unsigned int old;
if(args.Length() < 1) {
old = umask(0);
umask((mode_t)old);
}
else if(!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);
else {
old = umask((mode_t)args[0]->Uint32Value());
}
return scope.Close(Uint32::New(old));
}

View File

@ -3,4 +3,10 @@ process.mixin(require("../common"));
var mask = 0664;
var old = process.umask(mask);
assert.equal(true, mask === process.umask(old));
assert.equal(mask, process.umask(old));
// confirm reading the umask does not modify it.
// 1. If the test fails, this call will succeed, but the mask will be set to 0
assert.equal(old, process.umask());
// 2. If the test fails, process.umask() will return 0
assert.equal(old, process.umask());