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 26 public: 27 KPath(size_t bufferSize = B_PATH_NAME_LENGTH); 28 KPath(const char* path, int32 flags = DEFAULT, 29 size_t bufferSize = B_PATH_NAME_LENGTH); 30 KPath(const KPath& other); 31 ~KPath(); 32 33 status_t SetTo(const char* path, int32 flags = DEFAULT, 34 size_t bufferSize = B_PATH_NAME_LENGTH); 35 void Adopt(KPath& other); 36 37 status_t InitCheck() const; 38 39 status_t SetPath(const char* path, 40 int32 flags = DEFAULT); 41 const char* Path() const; Length()42 size_t Length() const 43 { return fPathLength; } 44 BufferSize()45 size_t BufferSize() const 46 { return fBufferSize; } 47 char* LockBuffer(bool force = false); 48 void UnlockBuffer(); 49 char* DetachBuffer(); 50 51 const char* Leaf() const; 52 status_t ReplaceLeaf(const char* newLeaf); 53 bool RemoveLeaf(); 54 // returns false, if nothing could be removed anymore 55 56 status_t Append(const char* toAppend, 57 bool isComponent = true); 58 59 status_t Normalize(bool traverseLeafLink); 60 61 KPath& operator=(const KPath& other); 62 KPath& operator=(const char* path); 63 64 bool operator==(const KPath& other) const; 65 bool operator==(const char* path) const; 66 bool operator!=(const KPath& other) const; 67 bool operator!=(const char* path) const; 68 69 private: 70 status_t _AllocateBuffer(); 71 void _FreeBuffer(); 72 status_t _Normalize(const char* path, 73 bool traverseLeafLink); 74 void _ChopTrailingSlashes(); 75 76 private: 77 char* fBuffer; 78 size_t fBufferSize; 79 size_t fPathLength; 80 bool fLocked; 81 bool fLazy; 82 bool fFailed; 83 bool fIsNull; 84 }; 85 86 87 } // namespace DiskDevice 88 } // namespace BPrivate 89 90 91 using BPrivate::DiskDevice::KPath; 92 93 94 #endif /* _K_PATH_H */ 95