* Added private header defining __gUmask which is now used everywhere where

needed.
* Some cleanup in Directory.cpp, and File.cpp.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31086 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-06-17 14:09:40 +00:00
parent 0bb8521b68
commit 160f2d1081
8 changed files with 96 additions and 88 deletions
+14
View File
@@ -0,0 +1,14 @@
/*
* Copyright 2009, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef UMASK_H
#define UMASK_H
#include <sys/types.h>
extern mode_t __gUmask;
#endif /* UMASK_H */
+18 -13
View File
@@ -24,10 +24,7 @@
#include <SymLink.h> #include <SymLink.h>
#include <syscalls.h> #include <syscalls.h>
#include <umask.h>
extern mode_t __gUmask;
// declared in sys/umask.c
//! Creates an uninitialized BDirectory object. //! Creates an uninitialized BDirectory object.
@@ -404,22 +401,25 @@ BDirectory::IsRootDirectory() const
status_t status_t
BDirectory::FindEntry(const char* path, BEntry* entry, bool traverse) const BDirectory::FindEntry(const char* path, BEntry* entry, bool traverse) const
{ {
status_t error = (path && entry ? B_OK : B_BAD_VALUE); if (path == NULL || entry == NULL)
if (entry) return B_BAD_VALUE;
entry->Unset(); entry->Unset();
if (error == B_OK) {
// init a potentially abstract entry // init a potentially abstract entry
status_t status;
if (InitCheck() == B_OK) if (InitCheck() == B_OK)
error = entry->SetTo(this, path, traverse); status = entry->SetTo(this, path, traverse);
else else
error = entry->SetTo(path, traverse); status = entry->SetTo(path, traverse);
// fail, if entry is abstract // fail, if entry is abstract
if (error == B_OK && !entry->Exists()) { if (status == B_OK && !entry->Exists()) {
error = B_ENTRY_NOT_FOUND; status = B_ENTRY_NOT_FOUND;
entry->Unset(); entry->Unset();
} }
}
return error; return status;
} }
@@ -778,6 +778,7 @@ BDirectory::CreateFile(const char *path, BFile *file, bool failIfExists)
{ {
if (!path) if (!path)
return B_BAD_VALUE; return B_BAD_VALUE;
// Let BFile do the dirty job. // Let BFile do the dirty job.
uint32 openMode = B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE uint32 openMode = B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE
| (failIfExists ? B_FAIL_IF_EXISTS : 0); | (failIfExists ? B_FAIL_IF_EXISTS : 0);
@@ -944,6 +945,7 @@ create_directory(const char *path, mode_t mode)
{ {
if (!path) if (!path)
return B_BAD_VALUE; return B_BAD_VALUE;
// That's the strategy: We start with the first component of the supplied // That's the strategy: We start with the first component of the supplied
// path, create a BPath object from it and successively add the following // path, create a BPath object from it and successively add the following
// components. Each time we get a new path, we check, if the entry it // components. Each time we get a new path, we check, if the entry it
@@ -959,6 +961,7 @@ create_directory(const char *path, mode_t mode)
component, nextComponent); component, nextComponent);
if (error != B_OK) if (error != B_OK)
return error; return error;
// append it to the BPath // append it to the BPath
if (dirPath.InitCheck() == B_NO_INIT) // first component if (dirPath.InitCheck() == B_NO_INIT) // first component
error = dirPath.SetTo(component); error = dirPath.SetTo(component);
@@ -968,11 +971,13 @@ create_directory(const char *path, mode_t mode)
if (error != B_OK) if (error != B_OK)
return error; return error;
path += nextComponent; path += nextComponent;
// create a BEntry from the BPath // create a BEntry from the BPath
BEntry entry; BEntry entry;
error = entry.SetTo(dirPath.Path(), true); error = entry.SetTo(dirPath.Path(), true);
if (error != B_OK) if (error != B_OK)
return error; return error;
// check, if it exists // check, if it exists
if (entry.Exists()) { if (entry.Exists()) {
// yep, it exists // yep, it exists
+8 -17
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008, Haiku Inc. * Copyright 2002-2009, Haiku Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -19,16 +19,12 @@
#include "storage_support.h" #include "storage_support.h"
#include <syscalls.h> #include <syscalls.h>
#include <umask.h>
extern mode_t __gUmask;
// declared in sys/umask.c
//! Creates an uninitialized BFile. //! Creates an uninitialized BFile.
BFile::BFile() BFile::BFile()
: BNode(), :
BPositionIO(),
fMode(0) fMode(0)
{ {
} }
@@ -39,8 +35,7 @@ BFile::BFile()
\param file the BFile object to be copied \param file the BFile object to be copied
*/ */
BFile::BFile(const BFile &file) BFile::BFile(const BFile &file)
: BNode(), :
BPositionIO(),
fMode(0) fMode(0)
{ {
*this = file; *this = file;
@@ -54,8 +49,7 @@ BFile::BFile(const BFile &file)
\see SetTo() for values for \a openMode \see SetTo() for values for \a openMode
*/ */
BFile::BFile(const entry_ref *ref, uint32 openMode) BFile::BFile(const entry_ref *ref, uint32 openMode)
: BNode(), :
BPositionIO(),
fMode(0) fMode(0)
{ {
SetTo(ref, openMode); SetTo(ref, openMode);
@@ -69,8 +63,7 @@ BFile::BFile(const entry_ref *ref, uint32 openMode)
\see SetTo() for values for \a openMode \see SetTo() for values for \a openMode
*/ */
BFile::BFile(const BEntry *entry, uint32 openMode) BFile::BFile(const BEntry *entry, uint32 openMode)
: BNode(), :
BPositionIO(),
fMode(0) fMode(0)
{ {
SetTo(entry, openMode); SetTo(entry, openMode);
@@ -84,8 +77,7 @@ BFile::BFile(const BEntry *entry, uint32 openMode)
\see SetTo() for values for \a openMode \see SetTo() for values for \a openMode
*/ */
BFile::BFile(const char *path, uint32 openMode) BFile::BFile(const char *path, uint32 openMode)
: BNode(), :
BPositionIO(),
fMode(0) fMode(0)
{ {
SetTo(path, openMode); SetTo(path, openMode);
@@ -102,8 +94,7 @@ BFile::BFile(const char *path, uint32 openMode)
\see SetTo() for values for \a openMode \see SetTo() for values for \a openMode
*/ */
BFile::BFile(const BDirectory *dir, const char *path, uint32 openMode) BFile::BFile(const BDirectory *dir, const char *path, uint32 openMode)
: BNode(), :
BPositionIO(),
fMode(0) fMode(0)
{ {
SetTo(dir, path, openMode); SetTo(dir, path, openMode);
+1 -1
View File
@@ -4,7 +4,7 @@ SetSubDirSupportedPlatforms haiku libbe_test ;
UseLibraryHeaders icon ; UseLibraryHeaders icon ;
UsePrivateHeaders shared app storage ; UsePrivateHeaders app libroot shared storage ;
UsePrivateSystemHeaders ; UsePrivateSystemHeaders ;
# for libbe_test # for libbe_test
+1 -1
View File
@@ -1,6 +1,6 @@
SubDir HAIKU_TOP src system libroot posix sys ; SubDir HAIKU_TOP src system libroot posix sys ;
UsePrivateHeaders shared ; UsePrivateHeaders libroot shared ;
UsePrivateSystemHeaders ; UsePrivateSystemHeaders ;
MergeObject posix_sys.o : MergeObject posix_sys.o :
+3 -5
View File
@@ -1,16 +1,14 @@
/* /*
* Copyright 2002-2008, Axel Dörfler, [email protected]. * Copyright 2002-2009, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include <sys/stat.h> #include <sys/stat.h>
#include <syscalls.h>
#include <errno.h> #include <errno.h>
#include <syscalls.h>
extern mode_t __gUmask; #include <umask.h>
// declared in sys/umask.c
#define RETURN_AND_SET_ERRNO(err) \ #define RETURN_AND_SET_ERRNO(err) \
+5 -3
View File
@@ -1,13 +1,15 @@
/* /*
** Copyright 2004, Axel Dörfler, [email protected]. All rights reserved. * Copyright 2004-2009, Axel Dörfler, [email protected].
** Distributed under the terms of the Haiku License. * Distributed under the terms of the MIT License.
*/ */
#include <sys/stat.h> #include <sys/stat.h>
#include <syscalls.h>
#include <errno.h> #include <errno.h>
#include <syscalls.h>
#include <umask.h>
mode_t __gUmask = 022; mode_t __gUmask = 022;
// this must be made available to open() and friends // this must be made available to open() and friends
+4 -6
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2005, Axel Dörfler, [email protected]. All rights reserved. * Copyright 2002-2009, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Copyright 2001, Manuel J. Petit. All rights reserved. * Copyright 2001, Manuel J. Petit. All rights reserved.
@@ -13,16 +13,14 @@
#include <errno.h> #include <errno.h>
#include <syscalls.h> #include <syscalls.h>
#include <umask.h>
extern mode_t __gUmask;
// declared in sys/umask.c
int int
creat(const char *path, mode_t mode) creat(const char *path, mode_t mode)
{ {
int status = _kern_open(-1, path, O_CREAT | O_TRUNC | O_WRONLY, mode & ~__gUmask); int status = _kern_open(-1, path, O_CREAT | O_TRUNC | O_WRONLY,
mode & ~__gUmask);
// adapt the permissions as required by POSIX // adapt the permissions as required by POSIX
if (status < 0) { if (status < 0) {
errno = status; errno = status;