mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-25 08:21:08 +00:00
lib/libc: remove internal use of getcwd at fstatat
The implementation and behaviour of 'getcwd' is externally defined. Add move operators to Genode::Path. Issue: #1984
This commit is contained in:
parent
597cdc846c
commit
930e2638b2
@ -110,7 +110,7 @@ static void resolve_symlinks(char const *path, Absolute_path &resolved_path)
|
|||||||
throw Symlink_resolve_error();
|
throw Symlink_resolve_error();
|
||||||
}
|
}
|
||||||
|
|
||||||
current_iteration_working_path.import(next_iteration_working_path.base());
|
current_iteration_working_path = next_iteration_working_path;
|
||||||
PDBGV("current_iteration_working_path = %s", current_iteration_working_path.base());
|
PDBGV("current_iteration_working_path = %s", current_iteration_working_path.base());
|
||||||
|
|
||||||
next_iteration_working_path.import("");
|
next_iteration_working_path.import("");
|
||||||
@ -184,7 +184,7 @@ static void resolve_symlinks(char const *path, Absolute_path &resolved_path)
|
|||||||
|
|
||||||
} while (symlink_resolved_in_this_iteration);
|
} while (symlink_resolved_in_this_iteration);
|
||||||
|
|
||||||
resolved_path.import(next_iteration_working_path.base());
|
resolved_path = next_iteration_working_path;
|
||||||
resolved_path.remove_trailing('/');
|
resolved_path.remove_trailing('/');
|
||||||
PDBGV("resolved_path = %s", resolved_path.base());
|
PDBGV("resolved_path = %s", resolved_path.base());
|
||||||
}
|
}
|
||||||
@ -363,7 +363,7 @@ extern "C" int fstatat(int libc_fd, char const *path, struct stat *buf, int flag
|
|||||||
Libc::Absolute_path abs_path;
|
Libc::Absolute_path abs_path;
|
||||||
|
|
||||||
if (libc_fd == AT_FDCWD) {
|
if (libc_fd == AT_FDCWD) {
|
||||||
getcwd(abs_path.base(), abs_path.capacity());
|
abs_path = cwd();
|
||||||
abs_path.append("/");
|
abs_path.append("/");
|
||||||
abs_path.append(path);
|
abs_path.append(path);
|
||||||
} else {
|
} else {
|
||||||
|
@ -192,6 +192,8 @@ class Genode::Path_base
|
|||||||
|
|
||||||
void _strip_from_begin(unsigned count) { strip(_path, count); }
|
void _strip_from_begin(unsigned count) { strip(_path, count); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove superfluous artifacts from absolute path
|
* Remove superfluous artifacts from absolute path
|
||||||
*/
|
*/
|
||||||
@ -203,7 +205,9 @@ class Genode::Path_base
|
|||||||
remove_trailing('.', _path);
|
remove_trailing('.', _path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _import(char const *path, char const *pwd = 0)
|
public:
|
||||||
|
|
||||||
|
void import(char const *path, char const *pwd = 0)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Validate 'pwd' argument, if not supplied, enforce invariant
|
* Validate 'pwd' argument, if not supplied, enforce invariant
|
||||||
@ -237,18 +241,14 @@ class Genode::Path_base
|
|||||||
_canonicalize();
|
_canonicalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
Path_base(char *buf, size_t buf_len,
|
Path_base(char *buf, size_t buf_len,
|
||||||
char const *path, char const *pwd = 0)
|
char const *path, char const *pwd = 0)
|
||||||
:
|
:
|
||||||
_path(buf), _path_max_len(buf_len)
|
_path(buf), _path_max_len(buf_len)
|
||||||
{
|
{
|
||||||
_import(path, pwd);
|
import(path, pwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void import(char const *path, char const *pwd = 0) { _import(path, pwd); }
|
|
||||||
|
|
||||||
char *base() { return _path; }
|
char *base() { return _path; }
|
||||||
char const *base() const { return _path; }
|
char const *base() const { return _path; }
|
||||||
|
|
||||||
@ -345,6 +345,21 @@ class Genode::Path : public Path_base {
|
|||||||
: Path_base(_buf, sizeof(_buf), path, pwd) { }
|
: Path_base(_buf, sizeof(_buf), path, pwd) { }
|
||||||
|
|
||||||
constexpr size_t capacity() { return MAX_LEN; }
|
constexpr size_t capacity() { return MAX_LEN; }
|
||||||
|
|
||||||
|
Path& operator=(char const *path)
|
||||||
|
{
|
||||||
|
Genode::strncpy(_buf, path, MAX_LEN);
|
||||||
|
_canonicalize();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <unsigned N>
|
||||||
|
Path& operator=(Path<N> &other)
|
||||||
|
{
|
||||||
|
Genode::strncpy(_buf, other._buf, MAX_LEN);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _INCLUDE__OS__PATH_H_ */
|
#endif /* _INCLUDE__OS__PATH_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user