From 930e2638b290c6943521ab888cfca26efc68a1f3 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Tue, 31 May 2016 12:40:35 +0200 Subject: [PATCH] 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 --- .../libports/src/lib/libc/file_operations.cc | 6 ++--- repos/os/include/os/path.h | 27 ++++++++++++++----- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/repos/libports/src/lib/libc/file_operations.cc b/repos/libports/src/lib/libc/file_operations.cc index aafe14dd9..16c4edf95 100644 --- a/repos/libports/src/lib/libc/file_operations.cc +++ b/repos/libports/src/lib/libc/file_operations.cc @@ -110,7 +110,7 @@ static void resolve_symlinks(char const *path, Absolute_path &resolved_path) 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()); 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); - resolved_path.import(next_iteration_working_path.base()); + resolved_path = next_iteration_working_path; resolved_path.remove_trailing('/'); 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; if (libc_fd == AT_FDCWD) { - getcwd(abs_path.base(), abs_path.capacity()); + abs_path = cwd(); abs_path.append("/"); abs_path.append(path); } else { diff --git a/repos/os/include/os/path.h b/repos/os/include/os/path.h index 363b99a98..62024ec48 100644 --- a/repos/os/include/os/path.h +++ b/repos/os/include/os/path.h @@ -192,6 +192,8 @@ class Genode::Path_base void _strip_from_begin(unsigned count) { strip(_path, count); } + protected: + /** * Remove superfluous artifacts from absolute path */ @@ -203,7 +205,9 @@ class Genode::Path_base 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 @@ -237,18 +241,14 @@ class Genode::Path_base _canonicalize(); } - public: - Path_base(char *buf, size_t buf_len, char const *path, char const *pwd = 0) : _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 const *base() const { return _path; } @@ -345,6 +345,21 @@ class Genode::Path : public Path_base { : Path_base(_buf, sizeof(_buf), path, pwd) { } constexpr size_t capacity() { return MAX_LEN; } + + Path& operator=(char const *path) + { + Genode::strncpy(_buf, path, MAX_LEN); + _canonicalize(); + return *this; + } + + template + Path& operator=(Path &other) + { + Genode::strncpy(_buf, other._buf, MAX_LEN); + return *this; + } + }; #endif /* _INCLUDE__OS__PATH_H_ */