diff options
Diffstat (limited to 'src/command/cd.cc')
| -rw-r--r-- | src/command/cd.cc | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/src/command/cd.cc b/src/command/cd.cc index 49b1899..5434f20 100644 --- a/src/command/cd.cc +++ b/src/command/cd.cc @@ -1,10 +1,32 @@ #include "command/builtin.h" -namespace ov4::command -{ +#include <cerrno> +#include <unordered_map> using namespace std; +// constexpr string_view +// err_EACCES = "cd: Search permission is denied for one of the components of path.", +// err_EFAULT = "cd: path points outside your accessible address space.", +// err_EIO = "An I/O error occurred.", +// err_ENOTDIR = "A component of path is not a directory.", +// err_ENOENT = "The directory specified in path does not exist.", +// err_ENAMETOOLONG = "path is too long.", +// err_ENOMEM = "Insufficient kernel memory was available."; + +const unordered_map<int, string_view> err_list = { + { EACCES, "cd: Search permission is denied for one of the components of path." }, + { EFAULT, "cd: path points outside your accessible address space." }, + { EIO, "An I/O error occurred." }, + { ENOTDIR, "A component of path is not a directory." }, + { ENOENT, "The directory specified in path does not exist." }, + { ENAMETOOLONG, "path is too long." }, + { ENOMEM, "Insufficient kernel memory was available."}, +}; + +namespace ov4::command +{ + void cd(char **argv) { if (argv == nullptr) return; @@ -13,7 +35,16 @@ void cd(char **argv) cout << "cd: requires path" << endl; return; } - ov4::set_current_dir(argv[1]); + int ret = ov4::set_current_dir(argv[1]); + if (ret != 0) + { + if (err_list.find(errno) != err_list.end()) + { + cout << "cd: " << err_list.at(errno) << endl; + return; + } + cout << "cd: Error occured, code: " << errno << endl; + } } } |
