1 /* 2 * Copyright 2004-2008, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Copyright 2008-2017, Axel Dörfler, axeld@pinc-software.de. 4 * Distributed under the terms of the MIT License. 5 */ 6 #ifndef _K_PATH_H 7 #define _K_PATH_H 8 9 10 #include <KernelExport.h> 11 12 13 namespace BPrivate { 14 namespace DiskDevice { 15 16 17 class KPath { 18 public: 19 enum { 20 DEFAULT = 0, 21 NORMALIZE = 0x01, 22 TRAVERSE_LEAF_LINK = 0x02, 23 LAZY_ALLOC = 0x04 24 }; 25 public: 26 KPath(size_t bufferSize = B_PATH_NAME_LENGTH); 27 KPath(const char* path, int32 flags = DEFAULT, 28 size_t bufferSize = B_PATH_NAME_LENGTH); 29 KPath(const KPath& other); 30 ~KPath(); 31 32 status_t SetTo(const char* path, int32 flags = DEFAULT, 33 size_t bufferSize = B_PATH_NAME_LENGTH); 34 void Adopt(KPath& other); 35 36 status_t InitCheck() const; 37 38 status_t SetPath(const char* path, 39 int32 flags = DEFAULT); 40 const char* Path() const; 41 size_t Length() const 42 { return fPathLength; } 43 44 size_t BufferSize() const 45 { return fBufferSize; } 46 char* LockBuffer(bool force = false); 47 void UnlockBuffer(); 48 char* DetachBuffer(); 49 50 const char* Leaf() const; 51 status_t ReplaceLeaf(const char* newLeaf); 52 bool RemoveLeaf(); 53 // returns false, if nothing could be removed anymore 54 55 status_t Append(const char* toAppend, 56 bool isComponent = true); 57 58 status_t Normalize(bool traverseLeafLink); 59 60 KPath& operator=(const KPath& other); 61 KPath& operator=(const char* path); 62 63 bool operator==(const KPath& other) const; 64 bool operator==(const char* path) const; 65 bool operator!=(const KPath& other) const; 66 bool operator!=(const char* path) const; 67 68 private: 69 status_t _AllocateBuffer(); 70 status_t _Normalize(const char* path, 71 bool traverseLeafLink); 72 void _ChopTrailingSlashes(); 73 74 private: 75 char* fBuffer; 76 size_t fBufferSize; 77 size_t fPathLength; 78 bool fLocked; 79 bool fLazy; 80 bool fFailed; 81 bool fIsNull; 82 }; 83 84 85 } // namespace DiskDevice 86 } // namespace BPrivate 87 88 89 using BPrivate::DiskDevice::KPath; 90 91 92 #endif /* _K_PATH_H */ 93