_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
This commit is contained in:
Axel Dörfler 2005-02-02 06:22:40 +00:00
parent 503950421d
commit 72b8a30907
1 changed files with 23 additions and 19 deletions

View File

@ -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 <stdarg.h>
#include <unistd.h>
@ -14,11 +15,15 @@
#include <syscalls.h>
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;