aboutsummaryrefslogtreecommitdiff
path: root/src/command
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-09-01 08:40:18 +0000
committer_ov4 <ov4@ov4.org>2026-09-01 08:40:18 +0000
commit22ee3d7ca978cddf87c132e2271df0cb47b4a99e (patch)
treeeab79c8683d96fcb150c6ead7528935ceab697f2 /src/command
parent3827fc4543f55ff33ed657625b68ca628917188c (diff)
cd
Diffstat (limited to 'src/command')
-rw-r--r--src/command/cd.cc37
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;
+ }
}
}