Minor style cleanup.
This commit is contained in:
@@ -13,59 +13,66 @@ namespace BPrivate {
|
||||
namespace DiskDevice {
|
||||
|
||||
class KPath {
|
||||
public:
|
||||
KPath(size_t bufferSize = B_PATH_NAME_LENGTH);
|
||||
KPath(const char* path, bool normalize = false,
|
||||
size_t bufferSize = B_PATH_NAME_LENGTH);
|
||||
KPath(const KPath& other);
|
||||
~KPath();
|
||||
public:
|
||||
KPath(size_t bufferSize = B_PATH_NAME_LENGTH);
|
||||
KPath(const char* path, bool normalize = false,
|
||||
size_t bufferSize = B_PATH_NAME_LENGTH);
|
||||
KPath(const KPath& other);
|
||||
~KPath();
|
||||
|
||||
status_t SetTo(const char *path, bool normalize = false,
|
||||
size_t bufferSize = B_PATH_NAME_LENGTH,
|
||||
bool traverseLeafLink = false);
|
||||
void Adopt(KPath& other);
|
||||
status_t SetTo(const char* path, bool normalize = false,
|
||||
size_t bufferSize = B_PATH_NAME_LENGTH,
|
||||
bool traverseLeafLink = false);
|
||||
void Adopt(KPath& other);
|
||||
|
||||
status_t InitCheck() const;
|
||||
status_t InitCheck() const;
|
||||
|
||||
status_t SetPath(const char *path, bool normalize = false,
|
||||
bool traverseLeafLink = false);
|
||||
const char *Path() const;
|
||||
size_t Length() const { return fPathLength; }
|
||||
status_t SetPath(const char* path,
|
||||
bool normalize = false,
|
||||
bool traverseLeafLink = false);
|
||||
const char* Path() const;
|
||||
size_t Length() const
|
||||
{ return fPathLength; }
|
||||
|
||||
size_t BufferSize() const { return fBufferSize; }
|
||||
char *LockBuffer();
|
||||
void UnlockBuffer();
|
||||
char* DetachBuffer();
|
||||
size_t BufferSize() const
|
||||
{ return fBufferSize; }
|
||||
char* LockBuffer();
|
||||
void UnlockBuffer();
|
||||
char* DetachBuffer();
|
||||
|
||||
const char *Leaf() const;
|
||||
status_t ReplaceLeaf(const char *newLeaf);
|
||||
bool RemoveLeaf();
|
||||
// returns false, if nothing could be removed anymore
|
||||
const char* Leaf() const;
|
||||
status_t ReplaceLeaf(const char* newLeaf);
|
||||
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);
|
||||
status_t Normalize(bool traverseLeafLink);
|
||||
|
||||
KPath& operator=(const KPath& other);
|
||||
KPath& operator=(const char* path);
|
||||
KPath& operator=(const KPath& other);
|
||||
KPath& operator=(const char* path);
|
||||
|
||||
bool operator==(const KPath& other) const;
|
||||
bool operator==(const char* path) const;
|
||||
bool operator!=(const KPath& other) const;
|
||||
bool operator!=(const char* path) const;
|
||||
bool operator==(const KPath& other) const;
|
||||
bool operator==(const char* path) const;
|
||||
bool operator!=(const KPath& other) const;
|
||||
bool operator!=(const char* path) const;
|
||||
|
||||
private:
|
||||
void _ChopTrailingSlashes();
|
||||
private:
|
||||
void _ChopTrailingSlashes();
|
||||
|
||||
char* fBuffer;
|
||||
size_t fBufferSize;
|
||||
size_t fPathLength;
|
||||
bool fLocked;
|
||||
char* fBuffer;
|
||||
size_t fBufferSize;
|
||||
size_t fPathLength;
|
||||
bool fLocked;
|
||||
};
|
||||
|
||||
|
||||
} // namespace DiskDevice
|
||||
} // namespace BPrivate
|
||||
|
||||
|
||||
using BPrivate::DiskDevice::KPath;
|
||||
|
||||
|
||||
#endif /* _K_PATH_H */
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
|
||||
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';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user