BNode: Style fixes, see below for details
Remove superfluous parens Rename result variable to bytesWritten Sync() Unwrap ternary style fix (for consistency) * Shouldn't this return fCStatus instead of B_FILE ERROR? * BeBook says "returning B_OK on success and an appropriate error message otherwise." * Has returned B_FILE_ERROR since "it is accomplished ..." Rename result variable to bytesWritten (again) Remove superfluous space explictly cast status_t to ssize_t Remove superfluous parens, remove space, add newline Explicitly cast status_t to ssize_t (again) WriteAttrString() cleanup * rename error to result * rename sizeWritten to bytesWritten (consistency and clarity) * check if error cede from WriteAttr and cast to status_t * > not entirely style but functionaly same * if length is different then written return B_FILE_ERROR * > not a style change but a very minor functional change * add some comments Tiny documentation fix precede vars with \a More style fixes * Rename error to result * Put parens around conditional of ternary instead of whole thing * Compare against NULL explicitly * Don't set fCStatus here, we're going to set it in the calling function instead * > note that Unset() sets fCStatus to B_NO_INIT but that's ok 80 char limit style fix More style fixes and don't set fCStatus * remove superfluous parens * compare ref to NULL explicitly * > Also don't set fCStatus here since we will do that in calling function Unset() sets fCStatus to B_NO_INIT but that's ok Unwrap ternary style fix (consistency) Rename error to result (again)
This commit is contained in:
parent
19d8d9fa39
commit
89c0b71c9a
@ -60,7 +60,7 @@ node_ref::node_ref(const node_ref& other)
|
||||
bool
|
||||
node_ref::operator==(const node_ref& other) const
|
||||
{
|
||||
return (device == other.device && node == other.node);
|
||||
return device == other.device && node == other.node;
|
||||
}
|
||||
|
||||
|
||||
@ -235,7 +235,10 @@ BNode::Unlock()
|
||||
status_t
|
||||
BNode::Sync()
|
||||
{
|
||||
return (fCStatus != B_OK) ? B_FILE_ERROR : _kern_fsync(fFd);
|
||||
if (fCStatus != B_OK)
|
||||
return B_FILE_ERROR;
|
||||
|
||||
return _kern_fsync(fFd);
|
||||
}
|
||||
|
||||
|
||||
@ -244,14 +247,15 @@ BNode::WriteAttr(const char* attr, type_code type, off_t offset,
|
||||
const void* buffer, size_t length)
|
||||
{
|
||||
if (fCStatus != B_OK)
|
||||
return B_FILE_ERROR;
|
||||
return (ssize_t)B_FILE_ERROR;
|
||||
|
||||
if (attr == NULL || buffer == NULL)
|
||||
return B_BAD_VALUE;
|
||||
return (ssize_t)B_BAD_VALUE;
|
||||
|
||||
ssize_t result = fs_write_attr(fFd, attr, type, offset, buffer, length);
|
||||
ssize_t bytesWritten = fs_write_attr(fFd, attr, type, offset, buffer,
|
||||
length);
|
||||
|
||||
return result < 0 ? errno : result;
|
||||
return bytesWritten < 0 ? (ssize_t)errno : bytesWritten;
|
||||
}
|
||||
|
||||
|
||||
@ -260,14 +264,14 @@ BNode::ReadAttr(const char* attr, type_code type, off_t offset,
|
||||
void* buffer, size_t length) const
|
||||
{
|
||||
if (fCStatus != B_OK)
|
||||
return B_FILE_ERROR;
|
||||
return (ssize_t)B_FILE_ERROR;
|
||||
|
||||
if (attr == NULL || buffer == NULL)
|
||||
return B_BAD_VALUE;
|
||||
return (ssize_t)B_BAD_VALUE;
|
||||
|
||||
ssize_t result = fs_read_attr(fFd, attr, type, offset, buffer, length);
|
||||
ssize_t bytesRead = fs_read_attr(fFd, attr, type, offset, buffer, length);
|
||||
|
||||
return result == -1 ? errno : result;
|
||||
return bytesRead == -1 ? (ssize_t)errno : bytesRead;
|
||||
}
|
||||
|
||||
|
||||
@ -297,7 +301,7 @@ BNode::GetAttrInfo(const char* name, struct attr_info* info) const
|
||||
if (name == NULL || info == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
return fs_stat_attr(fFd, name, info) < 0 ? errno : B_OK ;
|
||||
return fs_stat_attr(fFd, name, info) < 0 ? errno : B_OK;
|
||||
}
|
||||
|
||||
|
||||
@ -342,16 +346,23 @@ BNode::RewindAttrs()
|
||||
status_t
|
||||
BNode::WriteAttrString(const char* name, const BString* data)
|
||||
{
|
||||
status_t error = (!name || !data) ? B_BAD_VALUE : B_OK;
|
||||
if (error == B_OK) {
|
||||
status_t result = (name == NULL || data == NULL) ? B_BAD_VALUE : B_OK;
|
||||
if (result == B_OK) {
|
||||
int32 length = data->Length() + 1;
|
||||
ssize_t sizeWritten = WriteAttr(name, B_STRING_TYPE, 0, data->String(),
|
||||
ssize_t bytesWritten = WriteAttr(name, B_STRING_TYPE, 0, data->String(),
|
||||
length);
|
||||
if (sizeWritten != length)
|
||||
error = sizeWritten;
|
||||
if (bytesWritten < 0) {
|
||||
// error code returned by WriteAttr()
|
||||
result = (status_t)bytesWritten;
|
||||
} else if (bytesWritten != length) {
|
||||
// attribute partially written
|
||||
result = B_FILE_ERROR;
|
||||
}
|
||||
|
||||
// wrote exactly what we were supposed to, nothing more to do
|
||||
}
|
||||
|
||||
return error;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -401,10 +412,11 @@ BNode::operator=(const BNode& node)
|
||||
|
||||
// Close down out current state
|
||||
Unset();
|
||||
|
||||
// We have to manually dup the node, because R5::BNode::Dup()
|
||||
// is not declared to be const (which IMO is retarded).
|
||||
fFd = _kern_dup(node.fFd);
|
||||
fCStatus = (fFd < 0) ? B_NO_INIT : B_OK ;
|
||||
fCStatus = fFd < 0 ? B_NO_INIT : B_OK;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -521,7 +533,7 @@ BNode::set_status(status_t newStatus)
|
||||
|
||||
|
||||
/*! Initializes the BNode's file descriptor to the node referred to
|
||||
by the given FD and path combo.
|
||||
by the given \a fd and \a path combo.
|
||||
|
||||
\a path must either be \c NULL, an absolute or a relative path.
|
||||
In the first case, \a fd must not be \c NULL; the node it refers to will
|
||||
@ -550,8 +562,8 @@ BNode::_SetTo(int fd, const char* path, bool traverse)
|
||||
{
|
||||
Unset();
|
||||
|
||||
status_t error = (fd >= 0 || path ? B_OK : B_BAD_VALUE);
|
||||
if (error == B_OK) {
|
||||
status_t result = (fd >= 0 || path != NULL) ? B_OK : B_BAD_VALUE;
|
||||
if (result == B_OK) {
|
||||
int traverseFlag = (traverse ? 0 : O_NOTRAVERSE);
|
||||
fFd = _kern_open(fd, path, O_RDWR | O_CLOEXEC | traverseFlag, 0);
|
||||
if (fFd < B_OK && fFd != B_ENTRY_NOT_FOUND) {
|
||||
@ -559,10 +571,10 @@ BNode::_SetTo(int fd, const char* path, bool traverse)
|
||||
fFd = _kern_open(fd, path, O_RDONLY | O_CLOEXEC | traverseFlag, 0);
|
||||
}
|
||||
if (fFd < 0)
|
||||
error = fFd;
|
||||
result = fFd;
|
||||
}
|
||||
|
||||
return fCStatus = error;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -586,9 +598,9 @@ BNode::_SetTo(const entry_ref* ref, bool traverse)
|
||||
{
|
||||
Unset();
|
||||
|
||||
status_t result = (ref ? B_OK : B_BAD_VALUE);
|
||||
status_t result = ref != NULL ? B_OK : B_BAD_VALUE;
|
||||
if (result == B_OK) {
|
||||
int traverseFlag = (traverse ? 0 : O_NOTRAVERSE);
|
||||
int traverseFlag = traverse ? 0 : O_NOTRAVERSE;
|
||||
fFd = _kern_open_entry_ref(ref->device, ref->directory, ref->name,
|
||||
O_RDWR | O_CLOEXEC | traverseFlag, 0);
|
||||
if (fFd < B_OK && fFd != B_ENTRY_NOT_FOUND) {
|
||||
@ -600,7 +612,7 @@ BNode::_SetTo(const entry_ref* ref, bool traverse)
|
||||
result = fFd;
|
||||
}
|
||||
|
||||
return fCStatus = result;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -620,8 +632,7 @@ BNode::set_stat(struct stat& stat, uint32 what)
|
||||
if (fCStatus != B_OK)
|
||||
return B_FILE_ERROR;
|
||||
|
||||
return _kern_write_stat(fFd, NULL, false, &stat, sizeof(struct stat),
|
||||
what);
|
||||
return _kern_write_stat(fFd, NULL, false, &stat, sizeof(struct stat), what);
|
||||
}
|
||||
|
||||
|
||||
@ -651,9 +662,10 @@ BNode::InitAttrDir()
|
||||
status_t
|
||||
BNode::_GetStat(struct stat* stat) const
|
||||
{
|
||||
return fCStatus != B_OK
|
||||
? fCStatus
|
||||
: _kern_read_stat(fFd, NULL, false, stat, sizeof(struct stat));
|
||||
if (fCStatus != B_OK)
|
||||
return fCStatus;
|
||||
|
||||
return _kern_read_stat(fFd, NULL, false, stat, sizeof(struct stat));
|
||||
}
|
||||
|
||||
|
||||
@ -661,9 +673,9 @@ status_t
|
||||
BNode::_GetStat(struct stat_beos* stat) const
|
||||
{
|
||||
struct stat newStat;
|
||||
status_t error = _GetStat(&newStat);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
status_t result = _GetStat(&newStat);
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
|
||||
convert_to_stat_beos(&newStat, stat);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user