2006-03-05 21:11:59 +03:00
|
|
|
/*
|
2008-09-27 03:30:28 +04:00
|
|
|
* Copyright 2004-2008, Ingo Weinhold, ingo_weinhold@gmx.de.
|
2017-04-30 14:42:16 +03:00
|
|
|
* Copyright 2008-2017, Axel Dörfler, axeld@pinc-software.de.
|
2006-03-05 21:11:59 +03:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2004-10-28 01:41:16 +04:00
|
|
|
#ifndef _K_PATH_H
|
|
|
|
#define _K_PATH_H
|
|
|
|
|
2006-03-05 21:11:59 +03:00
|
|
|
|
2004-10-28 01:41:16 +04:00
|
|
|
#include <KernelExport.h>
|
|
|
|
|
2006-03-05 21:11:59 +03:00
|
|
|
|
2004-10-28 01:41:16 +04:00
|
|
|
namespace BPrivate {
|
|
|
|
namespace DiskDevice {
|
|
|
|
|
2017-04-30 17:31:28 +03:00
|
|
|
|
2004-10-28 01:41:16 +04:00
|
|
|
class KPath {
|
2017-04-30 14:42:16 +03:00
|
|
|
public:
|
|
|
|
enum {
|
|
|
|
DEFAULT = 0,
|
|
|
|
NORMALIZE = 0x01,
|
|
|
|
TRAVERSE_LEAF_LINK = 0x02,
|
2017-04-30 17:31:28 +03:00
|
|
|
LAZY_ALLOC = 0x04
|
2017-04-30 14:42:16 +03:00
|
|
|
};
|
2017-04-29 15:37:56 +03:00
|
|
|
public:
|
|
|
|
KPath(size_t bufferSize = B_PATH_NAME_LENGTH);
|
2017-04-30 14:42:16 +03:00
|
|
|
KPath(const char* path, int32 flags = DEFAULT,
|
2017-04-29 15:37:56 +03:00
|
|
|
size_t bufferSize = B_PATH_NAME_LENGTH);
|
|
|
|
KPath(const KPath& other);
|
|
|
|
~KPath();
|
|
|
|
|
2017-04-30 14:42:16 +03:00
|
|
|
status_t SetTo(const char* path, int32 flags = DEFAULT,
|
|
|
|
size_t bufferSize = B_PATH_NAME_LENGTH);
|
2017-04-29 15:37:56 +03:00
|
|
|
void Adopt(KPath& other);
|
|
|
|
|
|
|
|
status_t InitCheck() const;
|
|
|
|
|
|
|
|
status_t SetPath(const char* path,
|
2017-04-30 14:42:16 +03:00
|
|
|
int32 flags = DEFAULT);
|
2017-04-29 15:37:56 +03:00
|
|
|
const char* Path() const;
|
|
|
|
size_t Length() const
|
|
|
|
{ return fPathLength; }
|
|
|
|
|
|
|
|
size_t BufferSize() const
|
|
|
|
{ return fBufferSize; }
|
2017-04-30 17:31:28 +03:00
|
|
|
char* LockBuffer(bool force = false);
|
2017-04-29 15:37:56 +03:00
|
|
|
void UnlockBuffer();
|
|
|
|
char* DetachBuffer();
|
|
|
|
|
|
|
|
const char* Leaf() const;
|
|
|
|
status_t ReplaceLeaf(const char* newLeaf);
|
|
|
|
bool RemoveLeaf();
|
|
|
|
// returns false, if nothing could be removed anymore
|
|
|
|
|
|
|
|
status_t Append(const char* toAppend,
|
|
|
|
bool isComponent = true);
|
|
|
|
|
|
|
|
status_t Normalize(bool traverseLeafLink);
|
|
|
|
|
|
|
|
KPath& operator=(const KPath& other);
|
|
|
|
KPath& operator=(const char* path);
|
|
|
|
|
|
|
|
bool operator==(const KPath& other) const;
|
|
|
|
bool operator==(const char* path) const;
|
|
|
|
bool operator!=(const KPath& other) const;
|
|
|
|
bool operator!=(const char* path) const;
|
|
|
|
|
|
|
|
private:
|
2017-04-30 17:31:28 +03:00
|
|
|
status_t _AllocateBuffer();
|
|
|
|
status_t _Normalize(const char* path,
|
|
|
|
bool traverseLeafLink);
|
2017-04-29 15:37:56 +03:00
|
|
|
void _ChopTrailingSlashes();
|
|
|
|
|
2017-04-30 17:31:28 +03:00
|
|
|
private:
|
2017-04-29 15:37:56 +03:00
|
|
|
char* fBuffer;
|
|
|
|
size_t fBufferSize;
|
|
|
|
size_t fPathLength;
|
|
|
|
bool fLocked;
|
2017-04-30 17:31:28 +03:00
|
|
|
bool fLazy;
|
|
|
|
bool fFailed;
|
|
|
|
bool fIsNull;
|
2004-10-28 01:41:16 +04:00
|
|
|
};
|
|
|
|
|
2017-04-29 15:37:56 +03:00
|
|
|
|
2004-10-28 01:41:16 +04:00
|
|
|
} // namespace DiskDevice
|
|
|
|
} // namespace BPrivate
|
|
|
|
|
2017-04-29 15:37:56 +03:00
|
|
|
|
2004-10-28 01:41:16 +04:00
|
|
|
using BPrivate::DiskDevice::KPath;
|
|
|
|
|
2017-04-29 15:37:56 +03:00
|
|
|
|
2004-11-04 18:51:27 +03:00
|
|
|
#endif /* _K_PATH_H */
|