Added support for path normalization.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9625 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -13,15 +13,17 @@ namespace DiskDevice {
|
|||||||
class KPath {
|
class KPath {
|
||||||
public:
|
public:
|
||||||
KPath(int32 bufferSize = B_PATH_NAME_LENGTH);
|
KPath(int32 bufferSize = B_PATH_NAME_LENGTH);
|
||||||
KPath(const char* path, int32 bufferSize = B_PATH_NAME_LENGTH);
|
KPath(const char* path, bool normalize = false,
|
||||||
|
int32 bufferSize = B_PATH_NAME_LENGTH);
|
||||||
KPath(const KPath& other);
|
KPath(const KPath& other);
|
||||||
~KPath();
|
~KPath();
|
||||||
|
|
||||||
status_t SetTo(const char *path, int32 bufferSize = B_PATH_NAME_LENGTH);
|
status_t SetTo(const char *path, bool normalize = false,
|
||||||
|
int32 bufferSize = B_PATH_NAME_LENGTH);
|
||||||
|
|
||||||
status_t InitCheck() const;
|
status_t InitCheck() const;
|
||||||
|
|
||||||
status_t SetPath(const char *path);
|
status_t SetPath(const char *path, bool normalize = false);
|
||||||
const char *Path() const;
|
const char *Path() const;
|
||||||
int32 Length() const;
|
int32 Length() const;
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <KPath.h>
|
#include <KPath.h>
|
||||||
|
#include <team.h>
|
||||||
|
#include <vfs.h>
|
||||||
|
|
||||||
// debugging
|
// debugging
|
||||||
#define DBG(x)
|
#define DBG(x)
|
||||||
@@ -21,13 +23,13 @@ KPath::KPath(int32 bufferSize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
KPath::KPath(const char* path, int32 bufferSize)
|
KPath::KPath(const char* path, bool normalize, int32 bufferSize)
|
||||||
: fBuffer(NULL),
|
: fBuffer(NULL),
|
||||||
fBufferSize(0),
|
fBufferSize(0),
|
||||||
fPathLength(0),
|
fPathLength(0),
|
||||||
fLocked(false)
|
fLocked(false)
|
||||||
{
|
{
|
||||||
SetTo(path, bufferSize);
|
SetTo(path, normalize, bufferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy constructor
|
// copy constructor
|
||||||
@@ -48,7 +50,7 @@ KPath::~KPath()
|
|||||||
|
|
||||||
// SetTo
|
// SetTo
|
||||||
status_t
|
status_t
|
||||||
KPath::SetTo(const char* path, int32 bufferSize)
|
KPath::SetTo(const char* path, bool normalize, int32 bufferSize)
|
||||||
{
|
{
|
||||||
if (bufferSize <= 0)
|
if (bufferSize <= 0)
|
||||||
bufferSize = B_PATH_NAME_LENGTH;
|
bufferSize = B_PATH_NAME_LENGTH;
|
||||||
@@ -69,7 +71,7 @@ KPath::SetTo(const char* path, int32 bufferSize)
|
|||||||
fBufferSize = bufferSize;
|
fBufferSize = bufferSize;
|
||||||
fBuffer[0] = '\0';
|
fBuffer[0] = '\0';
|
||||||
}
|
}
|
||||||
return SetPath(path);
|
return SetPath(path, normalize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitCheck
|
// InitCheck
|
||||||
@@ -81,17 +83,29 @@ KPath::InitCheck() const
|
|||||||
|
|
||||||
// SetPath
|
// SetPath
|
||||||
status_t
|
status_t
|
||||||
KPath::SetPath(const char *path)
|
KPath::SetPath(const char *path, bool normalize)
|
||||||
{
|
{
|
||||||
if (!fBuffer)
|
if (!fBuffer)
|
||||||
return B_NO_INIT;
|
return B_NO_INIT;
|
||||||
if (path) {
|
if (path) {
|
||||||
int32 len = strlen(path);
|
if (normalize) {
|
||||||
if (len >= fBufferSize)
|
// normalize path
|
||||||
return B_BUFFER_OVERFLOW;
|
status_t error = vfs_normalize_path(path, fBuffer, fBufferSize,
|
||||||
memcpy(fBuffer, path, len + 1);
|
team_get_kernel_team_id() == team_get_current_team_id());
|
||||||
fPathLength = len;
|
if (error != B_OK) {
|
||||||
_ChopTrailingSlashes();
|
SetPath(NULL);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
fPathLength = strlen(fBuffer);
|
||||||
|
} else {
|
||||||
|
// don't normalize path
|
||||||
|
int32 len = strlen(path);
|
||||||
|
if (len >= fBufferSize)
|
||||||
|
return B_BUFFER_OVERFLOW;
|
||||||
|
memcpy(fBuffer, path, len + 1);
|
||||||
|
fPathLength = len;
|
||||||
|
_ChopTrailingSlashes();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fBuffer[0] = '\0';
|
fBuffer[0] = '\0';
|
||||||
fPathLength = 0;
|
fPathLength = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user