diff --git a/src/kernel/libroot/posix/unistd/open.c b/src/kernel/libroot/posix/unistd/open.c index 001b4abb59..bd25309dc7 100644 --- a/src/kernel/libroot/posix/unistd/open.c +++ b/src/kernel/libroot/posix/unistd/open.c @@ -1,10 +1,11 @@ -/* -** Copyright 2002-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -** -** Copyright 2001, Manuel J. Petit. All rights reserved. -** Distributed under the terms of the NewOS License. -*/ +/* + * Copyright 2002-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Copyright 2001, Manuel J. Petit. All rights reserved. + * Distributed under the terms of the NewOS License. + */ + #include #include @@ -14,11 +15,15 @@ #include +extern mode_t __gUmask; + // declared in sys/umask.c + + int creat(const char *path, mode_t mode) { - int status = _kern_create(path, O_CREAT | O_TRUNC | O_WRONLY, mode); - + int status = _kern_open(-1, path, O_CREAT | O_TRUNC | O_WRONLY, mode & ~__gUmask); + // adapt the permissions as required by POSIX if (status < 0) { errno = status; return -1; @@ -28,21 +33,20 @@ creat(const char *path, mode_t mode) int -open(const char *path, int oflags, ...) +open(const char *path, int openMode, ...) { int status; - int perms; + int perms = 0; va_list args; - va_start(args, oflags); - perms = va_arg(args,int); - va_end(args); - - if (oflags & O_CREAT) - status = _kern_create(path, oflags, perms); - else - status = _kern_open(-1, path, oflags); + if (openMode & O_CREAT) { + va_start(args, openMode); + perms = va_arg(args, int) & ~__gUmask; + // adapt the permissions as required by POSIX + va_end(args); + } + status = _kern_open(-1, path, openMode, perms); if (status < 0) { errno = status; return -1;