1 /* 2 * Copyright 2004-2008, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _K_PATH_H 6 #define _K_PATH_H 7 8 9 #include <KernelExport.h> 10 11 12 namespace BPrivate { 13 namespace DiskDevice { 14 15 class KPath { 16 public: 17 KPath(size_t bufferSize = B_PATH_NAME_LENGTH); 18 KPath(const char* path, bool normalize = false, 19 size_t bufferSize = B_PATH_NAME_LENGTH); 20 KPath(const KPath& other); 21 ~KPath(); 22 23 status_t SetTo(const char *path, bool normalize = false, 24 size_t bufferSize = B_PATH_NAME_LENGTH, 25 bool traverseLeafLink = false); 26 void Adopt(KPath& other); 27 28 status_t InitCheck() const; 29 30 status_t SetPath(const char *path, bool normalize = false, 31 bool traverseLeafLink = false); 32 const char *Path() const; 33 size_t Length() const { return fPathLength; } 34 35 size_t BufferSize() const { return fBufferSize; } 36 char *LockBuffer(); 37 void UnlockBuffer(); 38 char* DetachBuffer(); 39 40 const char *Leaf() const; 41 status_t ReplaceLeaf(const char *newLeaf); 42 bool RemoveLeaf(); 43 // returns false, if nothing could be removed anymore 44 45 status_t Append(const char *toAppend, bool isComponent = true); 46 47 status_t Normalize(bool traverseLeafLink); 48 49 KPath& operator=(const KPath& other); 50 KPath& operator=(const char* path); 51 52 bool operator==(const KPath& other) const; 53 bool operator==(const char* path) const; 54 bool operator!=(const KPath& other) const; 55 bool operator!=(const char* path) const; 56 57 private: 58 void _ChopTrailingSlashes(); 59 60 char* fBuffer; 61 size_t fBufferSize; 62 size_t fPathLength; 63 bool fLocked; 64 }; 65 66 } // namespace DiskDevice 67 } // namespace BPrivate 68 69 using BPrivate::DiskDevice::KPath; 70 71 #endif /* _K_PATH_H */ 72