aboutsummaryrefslogtreecommitdiff
path: root/src/command/cd.cc
blob: ecc511c8fb70a70c1dfbdd4b7b98c0ff68fd76e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

#include "command/builtin.h"

#include <cerrno>
#include <unordered_map>

using namespace std;

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;
    if (argv[1] == nullptr) 
    {
        cout << "cd: requires path" << endl;
        return;
    }
    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;
    }
}

}