KPath: Added LAZY_ALLOC flag.

* This allows KPath to not allocate a buffer when initialized
  without path.
* Added test cases for this.
* Added test for LockBuffer().
* Enhanced tests to allow building them in debug mode.
* Moved calling vfs_normalize_path() into own private method.
* Improved error codes; B_NO_MEMORY is now only returned if the
  allocation actually failed.
* If used with LAZY_ALLOC, Path() and LockBuffer() are now allowed
  to return a NULL path.
This commit is contained in:
Axel Dörfler
2017-04-30 17:14:45 +02:00
parent f94671c33d
commit e9843da357
4 changed files with 262 additions and 52 deletions
+10 -1
View File
@@ -13,12 +13,14 @@
namespace BPrivate {
namespace DiskDevice {
class KPath {
public:
enum {
DEFAULT = 0,
NORMALIZE = 0x01,
TRAVERSE_LEAF_LINK = 0x02,
LAZY_ALLOC = 0x04
};
public:
KPath(size_t bufferSize = B_PATH_NAME_LENGTH);
@@ -41,7 +43,7 @@ public:
size_t BufferSize() const
{ return fBufferSize; }
char* LockBuffer();
char* LockBuffer(bool force = false);
void UnlockBuffer();
char* DetachBuffer();
@@ -64,12 +66,19 @@ public:
bool operator!=(const char* path) const;
private:
status_t _AllocateBuffer();
status_t _Normalize(const char* path,
bool traverseLeafLink);
void _ChopTrailingSlashes();
private:
char* fBuffer;
size_t fBufferSize;
size_t fPathLength;
bool fLocked;
bool fLazy;
bool fFailed;
bool fIsNull;
};