xref: /haiku/headers/private/kernel/fs/KPath.h (revision 24159a0c7d6d6dcba9f2a0c1a7c08d2c8167f21b)
1 /*
2  * Copyright 2004-2006, Ingo Weinhold, bonefish@users.sf.net.
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 
26 		status_t InitCheck() const;
27 
28 		status_t SetPath(const char *path, bool normalize = false);
29 		const char *Path() const;
30 		size_t Length() const { return fPathLength; }
31 
32 		size_t BufferSize() const { return fBufferSize; }
33 		char *LockBuffer();
34 		void UnlockBuffer();
35 
36 		const char *Leaf() const;
37 		status_t ReplaceLeaf(const char *newLeaf);
38 
39 		status_t Append(const char *toAppend, bool isComponent = true);
40 
41 		KPath& operator=(const KPath& other);
42 		KPath& operator=(const char* path);
43 
44 		bool operator==(const KPath& other) const;
45 		bool operator==(const char* path) const;
46 		bool operator!=(const KPath& other) const;
47 		bool operator!=(const char* path) const;
48 
49 	private:
50 		void _ChopTrailingSlashes();
51 
52 		char*	fBuffer;
53 		size_t	fBufferSize;
54 		size_t	fPathLength;
55 		bool	fLocked;
56 };
57 
58 } // namespace DiskDevice
59 } // namespace BPrivate
60 
61 using BPrivate::DiskDevice::KPath;
62 
63 #endif	/* _K_PATH_H */
64