mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-19 03:06:39 +00:00
include/os/path.h: new path_from_label utility
Converts a session label hierarchy to a path hierarchy. Issue #1777 Issue #2060
This commit is contained in:
parent
e39dc445b1
commit
6018f594cf
@ -328,6 +328,11 @@ class Genode::Path_base
|
||||
return strcmp(_path, other) != 0;
|
||||
}
|
||||
|
||||
char const *last_element()
|
||||
{
|
||||
return last_element(_path)+1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print path to output stream
|
||||
*/
|
||||
@ -357,7 +362,7 @@ class Genode::Path : public Path_base {
|
||||
Path(char const *path, char const *pwd = 0)
|
||||
: Path_base(_buf, sizeof(_buf), path, pwd) { }
|
||||
|
||||
constexpr size_t capacity() { return MAX_LEN; }
|
||||
static constexpr size_t capacity() { return MAX_LEN; }
|
||||
|
||||
Path& operator=(char const *path)
|
||||
{
|
||||
@ -372,7 +377,44 @@ class Genode::Path : public Path_base {
|
||||
Genode::strncpy(_buf, other._buf, MAX_LEN);
|
||||
return *this;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
namespace Genode {
|
||||
|
||||
template <typename PATH>
|
||||
static inline PATH path_from_label(char const *label)
|
||||
{
|
||||
PATH path;
|
||||
|
||||
char tmp[path.capacity()];
|
||||
size_t len = strlen(label);
|
||||
|
||||
size_t i = 0;
|
||||
for (size_t j = 1; j < len; ++j) {
|
||||
if (!strcmp(" -> ", label+j, 4)) {
|
||||
path.append("/");
|
||||
|
||||
strncpy(tmp, label+i, (j-i)+1);
|
||||
/* rewrite any directory seperators */
|
||||
for (size_t k = 0; k < path.capacity(); ++k)
|
||||
if (tmp[k] == '/')
|
||||
tmp[k] = '_';
|
||||
path.append(tmp);
|
||||
|
||||
j += 4;
|
||||
i = j;
|
||||
}
|
||||
}
|
||||
path.append("/");
|
||||
strncpy(tmp, label+i, path.capacity());
|
||||
/* rewrite any directory seperators */
|
||||
for (size_t k = 0; k < path.capacity(); ++k)
|
||||
if (tmp[k] == '/')
|
||||
tmp[k] = '_';
|
||||
path.append(tmp);
|
||||
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__OS__PATH_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user