From 72b8a30907f14ad09c0c2f2c130839e618d8ee9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 2 Feb 2005 06:22:40 +0000 Subject: [PATCH] _kern_open() now has an additional parameter and replaces _kern_create(). Fixed permission handling - the umask is now correctly applied. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11206 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/libroot/posix/unistd/open.c | 42 ++++++++++++++------------ 1 file changed, 23 insertions(+), 19 deletions(-) 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;