diff --git a/headers/private/kernel/fs/KPath.h b/headers/private/kernel/fs/KPath.h index e1d2215139..5b4bbe4918 100644 --- a/headers/private/kernel/fs/KPath.h +++ b/headers/private/kernel/fs/KPath.h @@ -35,6 +35,8 @@ class KPath { 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); diff --git a/src/system/kernel/fs/KPath.cpp b/src/system/kernel/fs/KPath.cpp index ce6c006f91..e71aefeac6 100644 --- a/src/system/kernel/fs/KPath.cpp +++ b/src/system/kernel/fs/KPath.cpp @@ -202,6 +202,24 @@ KPath::ReplaceLeaf(const char *newLeaf) } +bool +KPath::RemoveLeaf() +{ + // get the leaf -- bail out, if not initialized or only the "/" is left + const char *leaf = Leaf(); + if (!leaf || leaf == fBuffer) + return false; + + // chop off the leaf + int32 leafIndex = leaf - fBuffer; + fBuffer[leafIndex] = '\0'; + fPathLength = leafIndex; + _ChopTrailingSlashes(); + + return true; +} + + status_t KPath::Append(const char *component, bool isComponent) {