Minor style cleanup.

This commit is contained in:
Axel Dörfler
2017-04-29 14:37:56 +02:00
parent ec39b68443
commit 3582d4fe85
2 changed files with 62 additions and 53 deletions
+11 -4
View File
@@ -27,12 +27,15 @@ class KPath {
status_t InitCheck() const;
status_t SetPath(const char *path, bool normalize = false,
status_t SetPath(const char* path,
bool normalize = false,
bool traverseLeafLink = false);
const char* Path() const;
size_t Length() const { return fPathLength; }
size_t Length() const
{ return fPathLength; }
size_t BufferSize() const { return fBufferSize; }
size_t BufferSize() const
{ return fBufferSize; }
char* LockBuffer();
void UnlockBuffer();
char* DetachBuffer();
@@ -42,7 +45,8 @@ class KPath {
bool RemoveLeaf();
// returns false, if nothing could be removed anymore
status_t Append(const char *toAppend, bool isComponent = true);
status_t Append(const char* toAppend,
bool isComponent = true);
status_t Normalize(bool traverseLeafLink);
@@ -63,9 +67,12 @@ class KPath {
bool fLocked;
};
} // namespace DiskDevice
} // namespace BPrivate
using BPrivate::DiskDevice::KPath;
#endif /* _K_PATH_H */
+16 -14
View File
@@ -3,7 +3,9 @@
* Distributed under the terms of the MIT License.
*/
/** A simple class wrapping a path. Has a fixed-sized buffer. */
/*! A simple class wrapping a path. Has a fixed-sized buffer. */
#include <fs/KPath.h>
@@ -66,7 +68,7 @@ KPath::SetTo(const char* path, bool normalize, size_t bufferSize,
bufferSize = B_PATH_NAME_LENGTH;
// free the previous buffer, if the buffer size differs
if (fBuffer && fBufferSize != bufferSize) {
if (fBuffer != NULL && fBufferSize != bufferSize) {
free(fBuffer);
fBuffer = NULL;
fBufferSize = 0;
@@ -75,14 +77,14 @@ KPath::SetTo(const char* path, bool normalize, size_t bufferSize,
fLocked = false;
// allocate buffer
if (!fBuffer)
if (fBuffer == NULL)
fBuffer = (char*)malloc(bufferSize);
if (!fBuffer)
if (fBuffer == NULL)
return B_NO_MEMORY;
if (fBuffer) {
fBufferSize = bufferSize;
fBuffer[0] = '\0';
}
return SetPath(path, normalize, traverseLeafLink);
}
@@ -196,7 +198,7 @@ KPath::DetachBuffer()
const char*
KPath::Leaf() const
{
if (!fBuffer)
if (fBuffer == NULL)
return NULL;
// only "/" has trailing slashes -- then we have to return the complete
@@ -215,7 +217,7 @@ status_t
KPath::ReplaceLeaf(const char* newLeaf)
{
const char* leaf = Leaf();
if (!leaf)
if (leaf == NULL)
return B_NO_INIT;
int32 leafIndex = leaf - fBuffer;
@@ -227,7 +229,7 @@ KPath::ReplaceLeaf(const char* newLeaf)
}
// if a leaf was given, append it
if (newLeaf)
if (newLeaf != NULL)
return Append(newLeaf);
return B_OK;
}
@@ -238,7 +240,7 @@ KPath::RemoveLeaf()
{
// get the leaf -- bail out, if not initialized or only the "/" is left
const char* leaf = Leaf();
if (!leaf || leaf == fBuffer)
if (leaf == NULL || leaf == fBuffer)
return false;
// chop off the leaf
@@ -330,9 +332,9 @@ KPath::operator==(const KPath& other) const
if (!fBuffer)
return !other.fBuffer;
return (other.fBuffer
return other.fBuffer
&& fPathLength == other.fPathLength
&& strcmp(fBuffer, other.fBuffer) == 0);
&& strcmp(fBuffer, other.fBuffer) == 0;
}
@@ -342,7 +344,7 @@ KPath::operator==(const char* path) const
if (!fBuffer)
return (!path);
return path && !strcmp(fBuffer, path);
return path && strcmp(fBuffer, path) == 0;
}
@@ -363,7 +365,7 @@ KPath::operator!=(const char* path) const
void
KPath::_ChopTrailingSlashes()
{
if (fBuffer) {
if (fBuffer != NULL) {
while (fPathLength > 1 && fBuffer[fPathLength - 1] == '/')
fBuffer[--fPathLength] = '\0';
}